我无法使用 web api 在 Sendgrid 上发送“安全”电子邮件。(平台 - .Net/C#、SendgridMail)
它适用于 http url (http://sendgrid.com/api/mail.send),但适用于 https (https://sendgrid.com/api/mail.send) 则失败。
private void SendMail()
{
var message = SendGrid.GenerateInstance();
//set the message recipients
message.AddTo("to@sonedomain.com1");
//set the sender
message.From = new MailAddress("from@somedomain.com1");
//set the message body
message.Html = "<html><p>Hello</p><p>World</p></html>";
//set the message subject
message.Subject = "Hello World HTML Test";
//create an instance of the Web transport mechanism
var transportInstance = SendGridMail.Transport.REST.GetInstance(new NetworkCredential("myusername", "mypassword"),"https://sendgrid.com/api/mail.send");
//send the mail
transportInstance.Deliver(message);
}
我得到一个 ArgumentException:未知元素:html。
进一步深入研究代码,我收到此错误:“400 Bad Request, The plain HTTP request was sent to HTTPS port, nginx/0.7.65”
注意
它适用于http url 即: (http://sendgrid.com/api/mail.send) 在上面的 GetInstance 函数中,而不是 (https://sendgrid.com/api/mail.send)。
通过浏览器发送电子邮件请求工作正常:(https://sendgrid.com/api/mail.send.json?to=to%40somedomain.com1&from=from%40somdomain.com1&subject=Test%20SG%20API&text=sometext&html=%3Cb% 3E%20test%20SG%20api%20body&api_user=sendgridusername&api_key=sendgridpassword)
对此的帮助表示赞赏。