Web 作业在 Azure 网站上引发 Smtp 异常

Web job throws Smtp exception on Azure website

我有一个 Web 作业,当它从 Azure poision q 中读取内容时试图发送电子邮件。

 public static void ProcessPoisonNotification(
        [QueueTrigger("parkingticketnotification-poison")] ParkingTicketNotificationBO notificationBo,
        TextWriter log)
    {
        var message = "xxx xxx xxx xxx xxx => POISON message: " + notificationBo.Dump();
        Console.WriteLine(message);
        log?.WriteLine(message);
        PoisonEmailNotifier.SendFailureMessage(notificationBo);
    }

电子邮件通知程序正在使用主 Web 应用程序中的代码,该应用程序可以发送电子邮件。但 Web 作业抛出以下异常。是因为 Web 应用程序阻塞了端口 25 吗?

看起来像 Windows 套接字错误代码 10013。您可以找到更多相关信息 here

Microsoft 有两个建议 - 您可能没有足够的权限,或者其他服务已绑定到目标端口。如果您知道端口 25 上的流量在您的主机上未打开,则很可能就是这个原因。但是,您可能有一些其他服务正在侦听该端口。

The Email notifier is using code from the main web applicaiton, which can send emails. but the Web job throws the following exception.

根据我的经验,Web应用和WebJob在同一个环境下,如果在Web应用中工作,那么在Azure WebJob中应该也能工作。

如果 WebJob 在本地运行,请尝试远程调试 WebJob。更多关于如何远程调试webjob的详细信息,请参考tutorials.

Note: Click the Settings tab, and change Configuration to Debug, before it is published.

此外,我们还可以使用Azure SendGrid轻松发送邮件。