【发布时间】:2016-04-23 22:58:10
【问题描述】:
我无法在 Azure 上配置的 MVC4 Web 应用程序上发送电子邮件。我可以在我的机器上本地发送电子邮件,但是当我将代码上传到云中的 azure 应用程序时,邮件传递并没有说它失败,但是电子邮件没有传递,SendGrid 没有报告邮件也在其仪表板上发送。
有人遇到过类似的问题吗?调查过类似的问题,但没有确切的答案。
我确实按照本文 (https://azure.microsoft.com/en-us/documentation/articles/sendgrid-dotnet-how-to-send-email/#reference) 的说明进行操作,但没有成功。还尝试通过 SendGrid 类库和使用普通 System.Net.Mail 发送电子邮件。
感谢任何帮助。
代码:
感谢您的回复。我正在使用 Web.DeliverAsync,这是我正在使用的代码:
// Create network credentials to access your SendGrid account
var username = System.Configuration.ConfigurationManager.AppSettings["smtpUser"];
var pswd = System.Configuration.ConfigurationManager.AppSettings["smtpPass"];
var credentials = new NetworkCredential(username, pswd);
// Create an Web transport for sending email.
SendGrid.Web transportWeb = new SendGrid.Web(credentials);
//var apiKey = System.Configuration.ConfigurationManager.AppSettings["sendgrid_api_key"];
var apiKey = "apikey";
SendGridMessage msg = new SendGridMessage();
msg.Subject = "...";
msg.AddTo(model.Email);
msg.Html = body;
msg.From = new MailAddress("...");
try
{
await transportWeb.DeliverAsync(msg);
}
catch (Exception e)
{
e.ToExceptionless().Submit();
ViewBag.ErrorMsg = e.Message;
return View("Error");
}
【问题讨论】:
-
请发布与您当前的问题和/或问题相关的实际代码。发布链接确实没有任何好处,特别是如果您没有完全按照代码执行,而代码在发布的链接中执行的操作。发布您正在使用的实际代码更容易,因此其他人可以尝试查明您遇到的问题是什么
-
感谢回复,附上代码示例。
-
这件事有什么更新吗?我有类似的问题。我的代码在 localhost 和 Azure Dev 站点中工作,但生产根本不发送任何邮件。
标签: c# asp.net-mvc-4 email azure sendgrid