I am trying to use a free SMTP relay from SendGrid to send emails from my ASP.NET application. I can connect to the server, but when I try to authenticate, I get this error : "The SMTP server has unexpectedly disconnected."
using (var client = new SmtpClient())
{
client.ServerCertificateValidationCallback =
(sender, certificate, certChainType, errors) => true;
client.AuthenticationMechanisms.Remove("XOAUTH2");
// connection
client.Connect("smtp.host", 465, true);
client.Authenticate("UserName", "Password");//error occurs here
client.Send(email);
client.Disconnect(true);
}
Once again, I can connect without any problem, but when I try to authenticate, I get the previously mentionned error...
Any suggestions?
Cheers
I solved my issue changing from SendGrid to gooogle's free SMTP service for all of their users. Simply follow the steps here and you should be good to go!