Send email on .net core application hosted on docker not work

76 Views Asked by At

"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);

    }
}
1

There are 1 best solutions below

0
Eriton Silva On

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/