Hello,
I'm trying to send an email using a SMTP server which has SSL enabled.
When I use .Net's SmtpClient, the email send successfully, but when I use Aspose's SmtpClient, it throws the following exception:
System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
I've added a handler to ServicePointManager.ServerCertificateValidationCallback, but it still throws this exception.
I've attached a sample project which shows the exception.
Are there any additional properties I need to set on Aspose's SmtpClient object to be able to send successfully?
Thanks,
Hi Jason,
Thank you for providing the sample application.
I am afraid, I am unable to observe the said exception by using the latest version of
Aspose.Email for .NET v1.6.0 and your provided sample application. I would request you to give the latest version a try and feed us back with your results.
I've tried with version 1.6.0 of Aspose.Email and I get the same error.
The SMTP server I'm connecting to was setup using a self-signed certificate for encryption.
I've attached my MSTest results file.
Let me know if there's any other information I can provide you with.
Hi Jason,
I am sorry for your trouble.
The test results clearly show the exception that I am unable to observe with Gmail Smtp server. Could you please arrange a test account on your server for a few days so I may pass the same to development team for investigation purposes?
Regards,
The SMTP server I was using is on my company's private intranet and I doubt that IT would be willing to share that out with the public.
I can also duplicate the issue with a Windows 2008 R2 system using the SMTP server you can install from Server Manager > Features.
Hi Jason,
Thank you for sharing your feedback.
I will further investigate the problem in the light of above comments and will share my findings shortly. We are sorry for your inconvenience.
Regards,
Hi Jason,
Thank you for your patience.
Upon discussing your said issue with the development team lead, I have learned that there are no means available to bypass the server certificate validation while using the current implementation of Aspose.Email.Mail.SmtpClient.
We believe that SmtpClient should have the ability to switch off server certificate validation at will. Therefore, I have logged a ticket (NETWORKNET-33235) in our tracking system to provide such functionality.
As soon as we have made some significant progress towards the resolution of this problem, we would be more than happy to update you with its status.
Regards,
The issues you have found earlier (filed as NETWORKNET-33235) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Hi,
Thanks for being patient for the resolution of this issue.
Please download the latest version of Aspose.Email v2.1.0. We have implemented this functionality in this version. You can now set the System.Net.ServicePointManager.ServerCertificateValidationCallback property to a method to use for custom validation by the client of the server certificate. Please have a look at the following code for your reference:
string host = "smtp.server.com";
int port = 25;
string username = "username";
string address = "address@abc.com";
string password = "password";
MailMessage message = new MailMessage(address, address, "NETWORKNET_33235", "Avoid expired/bad server certificate while using Aspose.Email.Mail.SmtpClient");
ServicePointManager.ServerCertificateValidationCallback = CheckCertificate;
using (SmtpClient client = new SmtpClient(host, port, username, password))
{
client.SecurityMode = SmtpSslSecurityMode.Implicit;
client.EnableSsl = true;
client.Send(message);
}
where CheckCertificate implements RemoteCertificateValidationCallback as follow:
public static bool CheckCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}