在sendgrid中使用X-SMTPAPI无法正常工作

时间:2016-12-07 15:04:48

标签: c# sendgrid

请帮忙!我是SendGrid的新手,我需要发送大量电子邮件,所以我在SendGrid上找到了这个X-SMTPAPI。问题是电子邮件只发送到“TO”。如果你愿意,你可以给出另一种方法。这是我的代码。

Email from = new Email(retsendemail.From);
Email to = new Email(retsendemail.To);
String subject = retsendemail.Subject;
Content content = new Content("text/html", retsendemail.Body);

Mail mail = new Mail(from, subject, to, content);

var header = new Header();

var recipients = new List<String> { "test1@xxx.com", "test2@xxx.com", "test3@xxx.com" };
header.SetTo(recipients);

var subs1 = new List<String> { "t1", "t2", "t3" };
header.AddSubstitution("%name%", subs1);

string jsonvalue = header.JsonString();

Dictionary<String, String> headers = new Dictionary<String, String>();
headers.Clear();
headers.Add("X-SMTPAPI", jsonvalue);

dynamic response = sg.client.mail.send.post(requestBody: mail.Get(), requestHeaders: headers).GetAwaiter().GetResult();
string statusCode = ((object)response.StatusCode).ToString();
string headerString = response.Headers.ToString() as string;

这是Jsonvalue:

{
    "to": [
        "test1@xxx.com",
        "test2@xxx.com",
        "test3@xxx.com"
    ],
    "sub": {
        "%name%": [
            "t1",
            "t2",
            "t3"
        ]
    }
}

0 个答案:

没有答案