使用 SendGrid 发送电子邮件
在我的本地(下面的代码)上工作得很好没有源代码控制,只需将相同代码的直接 WebDeploy 到 AzureWebsites 就会产生下面的错误。SendGrid 支持没有任何线索。
异常详细信息:System.Net.Sockets.SocketException:
[SocketException (0x271d): 试图以访问权限禁止的方式访问套接字]
CodeScales.Http.HttpClient.Navigate(HttpRequest 请求,HttpBehavior httpBehavior)+772 CodeScales.Http.HttpClient.Execute(HttpRequest 请求)+45 SendGridMail.Transport.REST.Deliver(ISendGrid 消息)+115
public bool SendEmail(string from, string to, string subject, string content)
{
var myMessage = SendGrid.GenerateInstance();
// Setup the email properties.
myMessage.From = new MailAddress(from);
myMessage.AddTo(to);
myMessage.Text = content;
myMessage.Subject = subject;
var username = "#####";
var pswd = "#####";
var credentials = new NetworkCredential(username, pswd);
// Get REST instance for sending email.
var transportREST = REST.GetInstance(credentials);
// Send the email.
transportREST.Deliver(myMessage);
return true;
}