SendGrid将类别添加到邮件

时间:2019-02-14 12:23:18

标签: 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 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);
    }
}

1 个答案:

答案 0 :(得分:1)

感谢Kami,我尝试了您的回答,它正常运行。

我将msg.AddHeader("category", "cat1");的这一行替换为msg.AddCategory("cat1");