【发布时间】:2019-02-14 12:23:18
【问题描述】:
我正在使用 SendGrid,我想在电子邮件中添加一个或多个类别,但添加的类别尚未发送!
这是代码:
internal class Example
{
private static void Main()
{
Execute().Wait();
}
static async Task Execute()
{
//FYI, the following three variables are not real
var apiKey = "SG.XXX";
var fromEmail = "";
var toEmail = "";
var client = new SendGridClient(apiKey);
var from = new EmailAddress(fromEmail);
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress(toEmail);
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
msg.AddHeader("category", "cat1"); //This line does nothing!
var response = await client.SendEmailAsync(msg);
}
}
【问题讨论】:
-
您使用哪个库来发送电子邮件?
-
我下载了这个 repo github.com/sendgrid/sendgrid-csharp 并添加了我的 ApiKey 并开始使用它
-
MailHelper.CreateSingleEmail返回一个具有Categories属性的SendGridMessage对象。见-github.com/sendgrid/sendgrid-csharp/blob/master/src/SendGrid/…。您应该能够分配给此属性以使类别起作用。虽然我同意标头应该可以工作,但它可能会被属性覆盖,具体取决于库如何生成请求。