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

.net 无法使用webapi在Sendgrid上发送安全电子邮件,.net,security,sendmail,sendgrid,.net,Security,Sendmail,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(); /

我无法使用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);
    }
private void SendMail()
{
var message=SendGrid.GenerateInstance();
//设置邮件收件人
message.AddTo(“to@sonedomain.com1");
//设置发件人
message.From=新邮件地址(“from@somedomain.com1");
//设置消息正文
message.Html=“你好

世界

”; //设置消息主题 message.Subject=“Hello World HTML测试”; //创建Web传输机制的实例 var transportInstance=SendGridMail.Transport.REST.GetInstance(新的网络凭据(“我的用户名”、“我的密码”),”https://sendgrid.com/api/mail.send"); //寄信 transportInstance.Deliver(消息); }
我得到一个ArgumentException:未知元素:html

进一步深入研究代码,我收到这个错误:“400错误请求,普通HTTP请求被发送到HTTPS端口,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)


非常感谢您的帮助。

我在SendGrid工作。我已经做了一些测试,这是C#包装的一个限制,特别是用于进行HTTP调用的CodeScales库。不幸的是,CodeScales根本不支持HTTPS。我在GitHub上发布了一个问题:


我将开始计划重构应用程序,以使用RestSharp进行API调用。抱歉给你添麻烦了

切换到amazon ses,我们做到了,它比sendgrid更专业,如果你知道如何正确设置sns,你也可以获得通知。我已经更新了C#包,因此HTTPS可以工作: