Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i am doing smtp first time for email verification in mvc

i dont no where i am wrong


when i register it shows me this error :-
Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated


here is my message service file

public async static Task SendEmailAsync(string email, string subject, string message)
      {
          try
          {
              var _email = "erjoshi@outlook.com";
              var _epass = ConfigurationManager.AppSettings["Emailpassword"];
              var _dispName = "HimanshuJoshi";
              MailMessage myMessage = new MailMessage();
              myMessage.To.Add(email);
              myMessage.From = new MailAddress(_email, _dispName);
              myMessage.Subject = subject;
              myMessage.Body = message;
              myMessage.IsBodyHtml = true;

              using (SmtpClient smtp = new SmtpClient())
              {
                  smtp.EnableSsl = true;
                  smtp.Host = "smtp.live.com";
                  smtp.Port = 587;
                  smtp.UseDefaultCredentials = false;
                  smtp.Credentials = new NetworkCredential(_email, _epass);
                  smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                  smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
                  await smtp.SendMailAsync(myMessage);
              }
          }
          catch (Exception ex)
          {

              throw ex;
          }


What I have tried:

i have added my email address here

after seeing this error i thing i am wrong some where here in this smtp code i dont know exectly where i am wrong
Posted
Updated 6-Mar-17 9:05am
v2

1 solution

Couple of thing to check:

1. make sure your email address is erjoshi@outlook.com, and not erjoshi@hotmail.com

2. Check if the account has two factor authentication/two step verification enabled, if yes, you need to set up an app password

3. Open another Hotmail/outlook account and use it for testing to eliminate any doubt :)
 
Share this answer
 
Comments
Himanshu.A.Joshi 6-Mar-17 15:06pm    
i have also tried by changing this to gmail

var _email = "er.hajoshi@gmail.com";
var _epass = ConfigurationManager.AppSettings["Emailpassword"];
var _dispName = "HimanshuJoshi";
MailMessage myMessage = new MailMessage();
myMessage.To.Add(email);
myMessage.From = new MailAddress(_email, _dispName);
myMessage.Subject = subject;
myMessage.Body = message;
myMessage.IsBodyHtml = true;

using (SmtpClient smtp = new SmtpClient())
{
smtp.EnableSsl = true;
smtp.Host = "smtp.gmail.com";
smtp.Port = 25;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(_email, _epass);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
await smtp.SendMailAsync(myMessage);
}

now it shows me error :-
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.130.108:25

i have also tried to use 587 as gmail port but not worked

what do you mean by two fector authentication ??
Bryian Tan 6-Mar-17 15:20pm    
Gmail port should be 587

http://www.c-sharpcorner.com/uploadfile/bryianTan/Asp-Net-send-email-using-gmail/

Also make sure your firewall/antivirus not blocking the connection.

Hotmail - About two-step verification[^]

Google 2-Step Verification[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900