【问题标题】:NodeMailer is blocked on Azure App ServiceNodeMailer 在 Azure 应用服务上被阻止
【发布时间】:2022-02-22 03:46:47
【问题描述】:

我有一个 NestJS 应用程序部署到 Windows Azure 应用程序服务。与 Azure 中的其他所有内容一样,它在我的机器上运行良好,直到我部署它。收到 500 错误。看起来像是某种端口限制。

错误信息:

DEBUG Creating transport: nodemailer (6.7.2; +https://nodemailer.com/; SMTP/6.7.2[client:6.7.2])
DEBUG Sending mail using SMTP/6.7.2 DEBUG [DJemKiOruKY] 
Resolved localhost as 127.0.0.1 [cache hit]
ERROR [DJemKiOruKY] connect EACCES 127.0.0.1:587
DEBUG [DJemKiOruKY] Closing connection to the server using 'destroy'

这是配置邮件程序的代码。我们的 noreply 电子邮件有一个自定义域 (noreply@our_company.com)

const transporter = nodemailer.createTransport({
            host: 'smtp.office365.com',
            port: 587,
            secure: false,
            requireTLS: true,
            auth: {
                user: process.env.NOREPLY_EMAIL_ADDRESS,
                pass: process.env.NOREPLY_EMAIL_PASSWORD
            },
            logger: true
        });

        const info = await transporter.sendMail({
            from: `Sender Name <${process.env.NOREPLY_EMAIL_ADDRESS}>`,
            to: process.env.NOREPLY_EMAIL_RECIPIENT,
            ...

【问题讨论】:

    标签: azure smtp nestjs nodemailer


    【解决方案1】:

    您必须明确允许端口 587 上的出站流量。

    如何执行此操作取决于您的设置。

    要验证端口是否打开,请转到应用服务控制台:

    tcpping smtp.office365.com:587
    

    【讨论】:

    • 这很奇怪,它奏效了。它做了 4 次尝试,所有 4 次都通过了
    • 你是否在 package.json 中添加了 Nodemailer 作为依赖项?
    • 是的,如果我不这样做,代码将无法编译......
    猜你喜欢
    • 2018-06-25
    • 2020-02-02
    • 1970-01-01
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    相关资源
    最近更新 更多