"I have a problem in my .NET Core application. I implemented a service to send emails using System.Net.Mail.
It works well when I run it in the localhost environment.
However, when I deploy it to a Docker host, I get a timeout. I am using the same host configuration in both environments, but in Docker, I encounter a timeout issue.
The application does not return an error, and it does not reach the catch statement."
public async Task<bool> SendEmailAsync(MailMessage message, EmailConfigDto config)
{
try
{
using SmtpClient smtpClient = new(config.StmpHost);
smtpClient.EnableSsl = false;
smtpClient.Credentials = new System.Net.NetworkCredential(config.StmpUsername, config.StmpPassword);
await smtpClient.SendMailAsync(message);
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
We discovered that my host has a policy that blocks emails sent by foreign servers. Since I am using a foreign server on AWS, my host blocked the emails. I followed the host's documentation to avoid this block.
https://king.host/wiki/artigo/como-ativar-o-smtp-internacional/