azure - Windows Azure辅助角色和SendGrid "Bad Key Path!"错误

标签 azure azure-worker-roles sendgrid

每当出现某些异常时,我都会尝试使用 SendGrid 从 Azure 辅助角色发送电子邮件,但我无法发送电子邮件。我正在使用 SendGridMail 版本 6.1.0.0 和 SendGrid.SmtpApi 版本 1.3.1.0,它们是通过 nuget 和 .Net 4.5 安装的。我目前正在本地调试,如果可以成功发送电子邮件,计划部署到 Azure。

SendGridMessage myMessage = new SendGridMessage();
List<String> recipients = new List<String> { @"John Doe <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6dcd9ded8d2f6d9c3c2dad9d9dd98d5d9db" rel="noreferrer noopener nofollow">[email protected]</a>>", @"Peter Howe <<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="473722353322352f28302207202a262e2b6924282a" rel="noreferrer noopener nofollow">[email protected]</a>>" };
myMessage.AddTo(recipients);
myMessage.From = new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f19c88949c90989db185948285df929e9c" rel="noreferrer noopener nofollow">[email protected]</a>");
myMessage.Subject = "Error in Update";
myMessage.Text = "TESTING 123";

string username = XXXXXX;

string password = XXXXXXX;
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential(username, password);

// Create an Web transport for sending email.
var transportWeb = new Web(credentials);

// Send the email.
await transportWeb.DeliverAsync(myMessage);

据我所知,除了当我调试并查看 myMessage header 有错误时,我没有收到任何错误。

当我尝试初始化一个新的空 header (var header = new Header();) 时,我注意到仍然存在错误

To = 'header.To' threw an exception of type 'System.ArgumentException' Message = "Bad key path!"

有人知道这是什么意思吗?或者这是否会导调用子邮件无法发送?

最佳答案

您的其他问题的答案实际上使用 SendGrid:

Alerts for exceptions in an Azure worker role

共有三个全局变量:

public const string SmtpServerHost = "smtp.sendgrid.net";
public const string SmtpServerUserName = "[<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d5d3c5d2c9c4c6d2cfcdd3c5cec4c7d2c9c4e0c1dad5d2c58ec3cfcd" rel="noreferrer noopener nofollow">[email protected]</a>]";
public const string SmtpServerPassword = "[password from sendgrid]";

您实际上不需要使用 SDK,只需在 Azure 门户中设置帐户,并将您的信用信息保存在您的项目中即可。

您可以在本地发送电子邮件,但如果您在工作网络上,防火墙可能会阻止电子邮件的发送。我发布的代码放置在我的命名空间中的电子邮件服务中。

关于azure - Windows Azure辅助角色和SendGrid "Bad Key Path!"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29995811/

相关文章:

.net - Windows Azure 辅助角色未通过第一行代码

Azure:从 Blob 存储下载会导致权限错误?

javascript - 如何不编码unicode,javascript

azure - 如何在逻辑应用程序中将内容类型应用程序八位字节流转换为 csv?

sql-server - 如何从本地实例查询/插入 Azure SQL Server

c# - 从辅助角色实例化辅助角色

azure - VirtoCommerce Azure 电子邮件提供商

javascript - SendGrid 客户端 TypeScript 错误 : HttpMethod

azure - 在 Gitlab 中加密 Terraform 值

c# - Azure AD API 始终将 System.Security.Principal.GenericIdentity.IsAuthenticated 返回为 false