I developed a C# application that uses MimeKit to send emails through SES. The following code demonstrates this Note: My server only allows the port - 25.
public virtual bool Send(MimeMail mimeMail)
{
try
{
mimeMailSmtpClient = new MailKit.Net.Smtp.SmtpClient();
mimeMailSmtpClient.Connect("email-smtp.us-west-2.amazonaws.com", 25,SecureSocketOptions.StartTls);
mimeMailSmtpClient.Authenticate(serverUsername, serverPassword);
mimeMailSmtpClient.Send(mimeMail.GetMessageItem());
mimeMailSmtpClient.Disconnect(true);
return true;
}
catch (Exception ex)
{
var msg = ex.Message;
return false;
}
}
When I execute my email sending function, I receive the following error:
An error occurred while attempting to establish an SSL or TLS connection.
The server's SSL certificate could not be validated for the following reasons:
• The server certificate has the following errors:
• The revocation function was unable to check revocation for the certificate.
• The revocation function was unable to check revocation because the revocation server was offline.
• An intermediate certificate has the following errors:
• The revocation function was unable to check revocation for the certificate.
• The revocation function was unable to check revocation because the revocation server was offline.
• An intermediate certificate has the following errors:
• The revocation function was unable to check revocation for the certificate.
• The revocation function was unable to check revocation because the revocation server was offline.
• An intermediate certificate has the following errors:
• The revocation function was unable to check revocation for the certificate.
• The revocation function was unable to check revocation because the revocation server was offline.
In PowerShell, I tried to enter the following command to connect to the Amazon SES SMTP server:
It connected successfully.
Am I missing any enabling part in my C# code?
Thanks
Change your code to either of these.
Disable SSL/TLS certificate revocation checks:
public virtual bool Send(MimeMail mimeMail)
{
try
{
mimeMailSmtpClient = new MailKit.Net.Smtp.SmtpClient();
mimeMailSmtpClient.CheckCertificateRevocation = false;
mimeMailSmtpClient.Connect("email-smtp.us-west-2.amazonaws.com", 25,SecureSocketOptions.StartTls);
mimeMailSmtpClient.Authenticate(serverUsername, serverPassword);
mimeMailSmtpClient.Send(mimeMail.GetMessageItem());
mimeMailSmtpClient.Disconnect(true);
return true;
}
catch (Exception ex)
{
var msg = ex.Message;
return false;
}
}
or disable STARTTLS:
public virtual bool Send(MimeMail mimeMail)
{
try
{
mimeMailSmtpClient = new MailKit.Net.Smtp.SmtpClient();
mimeMailSmtpClient.Connect("email-smtp.us-west-2.amazonaws.com", 25,SecureSocketOptions.None);
mimeMailSmtpClient.Authenticate(serverUsername, serverPassword);
mimeMailSmtpClient.Send(mimeMail.GetMessageItem());
mimeMailSmtpClient.Disconnect(true);
return true;
}
catch (Exception ex)
{
var msg = ex.Message;
return false;
}
}