“我的 .NET Core 应用程序出现问题。我实现了一项使用 System.Net.Mail 发送电子邮件的服务。
当我在本地主机环境中运行它时,效果很好。
但是,当我将其部署到 Docker 主机时,出现超时。我在两个环境中使用相同的主机配置,但在 Docker 中,我遇到了超时问题。
应用程序不返回错误,并且未到达 catch 语句。”
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);
}
}
我们发现我的主机有一项策略可以阻止外部服务器发送的电子邮件。由于我在 AWS 上使用外部服务器,因此我的主机阻止了电子邮件。我按照主机的文档来避免这个块。
https://king.host/wiki/artigo/como-ativar-o-smtp-internacional/