The SMTP server requires a secure connection or the client was not authenticated error while sending email from asp.net
I am trying to send an email from my asp.net application, the function worked fine on my machine, b开发者_JS百科ut when I deployed it on the webserver, I got the error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required,
Any one can help? Thanks
Finally I managed to solve it, The SSL should be enable on the webserver as well, here is a link to enable ssl on the IIS7
http://weblogs.asp.net/scottgu/archive/2007/04/06/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates.aspx
Please try this
private void MailSendThruGmail()
{
MailAddress fromAddress = new MailAddress("sender@gmail.com", "From Name");
MailAddress toAddress = new MailAddress("recipient@gmail.com", "To Name");
const string subject = "test";
const string body = @"Using this feature, you can send an e-mail message from an application very easily.";
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress.Address, toAddress.Address, subject, body);
msg.IsBodyHtml = true;
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("username", "password"),
EnableSsl = true
};
try
{
client.Send(msg);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
Go to your mail server and check your firewall settings. Then goto gmail, add your server address in gmail secured client list from account settings.
Are you part of a domain and the SMTP server is also on this domain. If this is the case, it could be that you are being authenticated by Windows authentication automatically and the user that IIS is running under is probably local to the machine it is on. You could either run the app pool under a domain user and use impersonation (not tested, but should work) or add some credentials to the SMTP server programatically when sending the email.
精彩评论