0

I deployed a ASP.NET Core 6 website on IONOS. I try to send emails (with my IONOS email) to validate the email address of a new user with MailKit 3.4.3.

Locally everything works fine, the email is sent correctly. But when I deploy the site on IONOS I have an error during the connection :

Error : The SMTP server has unexpectedly disconnected. 
Stack :  at MailKit.Net.Smtp.SmtpStream.ReadAheadAsync(CancellationToken cancellationToken)
   at MailKit.Net.Smtp.SmtpStream.ReadResponseAsync(CancellationToken cancellationToken)
   at MailKit.Net.Smtp.SmtpClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)

I contacted IONOS support several times, they confirm that the HOST address, the Port are correct and that there are no restrictions on their side, it should work...

My code :

using SmtpClient smtp = new(new ProtocolLogger("smtp.log"));
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
await smtp.ConnectAsync("mrelay.schlund.de", 587, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync(test@test.fr", "greatpwd");
smtp.Send(email);
smtp.Disconnect(true);

Any idea what I might be missing?

Atloka
  • 185
  • 3
  • 12
  • The code you provided includes a line that sets the `ServerCertificateValidationCallback` property to a lambda function that always returns `true`. This could potentially cause issues with the connection if the server's SSL/TLS certificate is not valid. You may want to consider using a more robust certificate validation callback function, such as one that checks the certificate against a trusted certificate authority. – Mahadi Hassan Dec 21 '22 at 23:53

1 Answers1

0

If it works on your dev box but not on your production server, that typically means it's a routing issue or a firewall issue.

jstedfast
  • 35,744
  • 5
  • 97
  • 110