在 docker 上托管的 .net core 应用程序上发送电子邮件不起作用

问题描述 投票:0回答:1

“我的 .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);

    }
}
.net docker smtpclient
1个回答
0
投票

我们发现我的主机有一项策略可以阻止外部服务器发送的电子邮件。由于我在 AWS 上使用外部服务器,因此我的主机阻止了电子邮件。我按照主机的文档来避免这个块。

https://king.host/wiki/artigo/como-ativar-o-smtp-internacional/

© www.soinside.com 2019 - 2024. All rights reserved.