【发布时间】:2020-01-06 19:25:00
【问题描述】:
我开发了一个 C# 控制台应用程序,在某些情况发生时向我们的客户发送电子邮件。将应用程序部署为 azure webjob 时不发送邮件。
在我的开发环境中从 Visual Studio 进行测试时,邮件按预期发送而没有任何问题,但当应用程序部署并作为 azure app-service webjob 运行时,不会发送邮件。当部署为 azure webjob 时,该应用程序也可以按预期工作。
public enum MailType : short { Plain, Html }
private static string MimeType(MailType type)
{ return (type == MailType.Html) ? "text/html" : "text/plain"; }
private static async Task sendMail(string to, string name, string subject, MailType mailType, string content)
{
SendGridMessage msg = new SendGridMessage();
msg.From = new EmailAddress("noreply@foo.org", "Foo Ltd.");
msg.AddTo(to, name);
msg.Subject = subject;
msg.AddContent(MimeType(mailType), content);
SendGridClient client = new SendGridClient(SendGridAPIKey);
await client.SendEmailAsync(msg);
}
public static void SendMail(string to, string name, string subject, MailType mailType, string content)
{
sendMail(to, name, subject, mailType, content).Wait();
}
关于这个问题的所有其他问题的答案(很多开发人员都遇到过这个问题)集中在代码上;特别是异步实现,但似乎这不是问题。 azure 对部署为 webjob 的应用程序和 sendgrid 服务器之间的通信是否有一些限制? (我正在使用 sendgrid 和 sendgrid.helpers.mail)
【问题讨论】:
-
当你将webjob发布到azure时,你有没有在azure webapp的
Configuration中设置SendGridAPIKey? -
检查 SendGridAPIKey 发现了一个错误,但修复它并没有解决问题。部署为 azure webjob 时来自应用程序的请求未记录在 SendGrid 活动列表中(但来自我的开发环境的请求)
-
你有没有解决过这个问题,如果有,解决方案是什么?
-
我没有解决 SendGrid 问题,而是使用 MailJet
标签: azure sendgrid sendgrid-api-v3