如何使用 C# 将抄送添加到 SendGrid 邮件

How to add CC to SendGrid mail using C#

这是我的代码..

var client = new SendGridClient(SendGridEmailEntity.Key);

var from = new EmailAddress(SendGridEmailEntity.Mail, SendGridEmailEntity.DisplayName);

var subject = templateRecord.EmailFrm.SubjectName;

var to = new EmailAddress(activeQueueEntities[i].EmailId, activeQueueEntities[i].Name);

var plainTextContent = "";

var htmlContent = templateRecord.TemplateContent;

var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);

Sendgrid 在其网站 api 中不支持 CC 参数。不过,您可以使用 SMTP api。如果 BCC 有帮助,您可以使用 sendGridMessage.SetBccSetting.

使用以下代码解决...

var client = new SendGridClient(SendGridEmailEntity.Key);
var from = new EmailAddress(SendGridEmailEntity.Mail, SendGridEmailEntity.DisplayName);
var subject = templateRecord.EmailFrm.SubjectName;
var to = new EmailAddress(activeQueueEntities[i].EmailId, activeQueueEntities[i].Name);
var htmlContent = templateRecord.TemplateContent;

var msg = new SendGridMessage()
    {
        From = from,
        Subject = subject,
        HtmlContent = htmlContent,
    };

msg.AddTo(to);
msg.AddCcs(CCs);