I am trying to send emails from my gmail account for testing. The code I am using is pasted below. I have checked the paramters that are being sent and they all are correct. Still I am facing exception "Error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required". I am not sure what am I doing wrong here!
public string MssSendEMail(string ssToAddress, string ssFromAddress, string ssSubject, string ssMessageBody, int ssSMTPPort, string ssSMTPHost, bool ssIsSSLEnabled, bool ssIsUsingDefaultCredentials, string ssUserName, string ssPassword)
{
string ssResult = "";
try
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress(ssFromAddress);
message.To.Add(new MailAddress(ssToAddress));
message.Subject = ssSubject;
message.IsBodyHtml = true;
message.Body = ssMessageBody;
smtp.Port = ssSMTPPort; //587
smtp.Host = ssSMTPHost; //smtp.gmail.com
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(ssUserName, ssPassword);
smtp.Send(message);
ssResult = "EMail Sent!";
}
catch (Exception ex)
{
ssResult = "Error: " + ex.Message;
}
return ssResult;
}