我正在尝试在Azure上使用SmtpClient和MailMessage方法将SendGrid集成到ASP.NET MVC应用程序中。
码:
MailMessage message = new MailMessage();
message.IsBodyHtml = true;
message.Subject = "Subject";
message.To.Add("To@MyDomain.com");
message.Body = "Body";
message.From = new MailAddress("From@MyDomain.com", "From Name");
SmtpClient client = new SmtpClient("smtp.sendgrid.net");
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("??", "SG.******");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 587; // I have tried with 25 and 2525
client.Timeout = 99999;
client.EnableSsl = false;
client.Send(message);
Run Code Online (Sandbox Code Playgroud)
我最终在Azure VM上的C#控制台应用程序和ASP.NET MVC应用程序中都遇到了此问题:
System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
Run Code Online (Sandbox Code Playgroud)
根据SendGrid网站上的文档avlb:https://sendgrid.com/docs/Classroom/Basics/Email_Infrastructure/recommended_smtp_settings.html
用户名和密码必须:使用字符串“ …