I am trying to send an email from my asp.net application, the function worked fine on my machine, but 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("[email protected]", "From Name");
MailAddress toAddress = new MailAddress("[email protected]", "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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With