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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
Please try this
private void MailSendThruGmail()
{
MailAddress fromAddress = new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3546505b515047755258545c591b565a58">[email protected]</a>", "From Name");
MailAddress toAddress = new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="522037313b223b373c2612353f333b3e7c313d3f">[email protected]</a>", "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());
}
}
Method 3
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.
Method 4
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0