C# 无法使用Sendgrid在Azure Web App上发送电子邮件
我无法在Azure上配置的MVC4 Web应用程序上发送电子邮件。我可以在我的机器上本地发送电子邮件,但当我将代码上传到云中的azure应用程序时,邮件传递并没有说失败,但没有发送电子邮件,SendGrid也没有报告邮件已在其仪表板上发送 有人遇到过类似的问题吗?研究过类似的问题,但没有确切的答案 我确实遵循了本文()的说明,但没有成功。还尝试通过SendGrid类库和使用plain System.Net.Mail发送电子邮件 感谢您的帮助 代码: 谢谢你的回复。我正在使用Web.DeliverAsync,这是我正在使用的代码:C# 无法使用Sendgrid在Azure Web App上发送电子邮件,c#,asp.net-mvc-4,email,azure,sendgrid,C#,Asp.net Mvc 4,Email,Azure,Sendgrid,我无法在Azure上配置的MVC4 Web应用程序上发送电子邮件。我可以在我的机器上本地发送电子邮件,但当我将代码上传到云中的azure应用程序时,邮件传递并没有说失败,但没有发送电子邮件,SendGrid也没有报告邮件已在其仪表板上发送 有人遇到过类似的问题吗?研究过类似的问题,但没有确切的答案 我确实遵循了本文()的说明,但没有成功。还尝试通过SendGrid类库和使用plain System.Net.Mail发送电子邮件 感谢您的帮助 代码: 谢谢你的回复。我正在使用Web.Deliver
// 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");
}
试试这个:
var apiKey = System.Configuration.ConfigurationManager.AppSettings["sendgrid_api_key"];
// Create an Web transport for sending email.
SendGrid.Web transportWeb = new SendGrid.Web(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");
}
另外,您使用的SendGrid C#库的版本是什么?确保其版本为6.3.x或更高版本。请发布与当前问题和/或问题相关的实际代码。发布一个链接真的没有任何好处,尤其是如果你没有在你的代码中做什么,而代码在发布的链接中做什么。更容易发布您正在使用的实际代码,以便其他人可以尝试查明您遇到的问题。感谢您的回复,随附代码示例。有关此问题的任何更新?我也有类似的问题。我的代码在localhost和Azure开发站点中工作,但生产部门根本不发送任何邮件。是的,我是。但是什么也没发生。