C# SendGrid将类别添加到邮件

C# SendGrid将类别添加到邮件,c#,asp.net,sendgrid,C#,Asp.net,Sendgrid,我正在使用SendGrid,我想向电子邮件添加一个或多个类别,但添加的类别尚未发送 代码如下: internal class Example { private static void Main() { Execute().Wait(); } static async Task Execute() { //FYI, the following three variables are not real var

我正在使用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);
    }
}
内部类示例
{
私有静态void Main()
{
Execute().Wait();
}
静态异步任务执行()
{
//仅供参考,以下三个变量不真实
var apiKey=“SG.XXX”;
var fromEmail=“”;
var toEmail=“”;
var client=新的SendGridClient(apiKey);
var from=新的电子邮件地址(fromEmail);
var subject=“使用SendGrid发送很有趣”;
var to=新电子邮件地址(toEmail);
var plainTextContent=“而且在任何地方都可以轻松完成,即使使用C#”;
var htmlContent=“并且在任何地方都可以轻松完成,即使使用C#”;
var msg=MailHelper.CreateSingleEmail(发件人、收件人、主题、明文内容、htmlContent);
msg.AddHeader(“category”、“cat1”);//此行不起任何作用!
var response=wait client.sendmailasync(msg);
}
}
谢谢,我试过了你的答案,效果很好


我替换了这一行
msg.AddHeader(“category”,“cat1”)带有
消息添加类别(“cat1”)

您使用哪个库发送电子邮件?我下载了此repo并添加了我的ApiKey,然后使用它
MailHelper。CreateSingleEmail
返回一个
SendGridMessage
对象,该对象具有
类别的属性。见-。您应该能够将类别分配给此属性以使其正常工作。虽然我同意头应该可以工作,但它可能会被属性覆盖,这取决于库如何生成请求。