小编use*_*155的帖子

无法使用webapi在Sendgrid上发送安全电子邮件

我无法使用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);
    }
Run Code Online (Sandbox Code Playgroud)

我得到一个ArgumentException:未知元素:html.

进一步向下钻取代码,我收到此错误:"400 Bad Request,普通HTTP请求被发送到HTTPS端口,nginx/0.7.65"

注意
它适用于上面的GetInstance函数中的http url ie:(http://sendgrid.com/api/mail.send)而不是(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)

对此的帮助表示赞赏.

.net security sendmail sendgrid

5
推荐指数
1
解决办法
1339
查看次数

标签 统计

.net ×1

security ×1

sendgrid ×1

sendmail ×1