【问题标题】:How to add CC to SendGrid mail using C#如何使用 C# 将 CC 添加到 SendGrid 邮件
【发布时间】:2020-07-17 08:01:57
【问题描述】:

这是我的代码..

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 sendgrid-templates


    【解决方案1】:

    已使用以下代码解决...

    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);
    

    【讨论】:

    • 这里需要注意的一点是,抄送或密送列表中的电子邮件地址不能与收件人列表中的相同,否则会引发错误(可能难以识别)。值得检查一下您是否在使其正常工作时遇到问题。
    【解决方案2】:

    Sendgrid 在其 web api 中不支持 CC 参数。不过,您可以使用 SMTP api。如果密件抄送有帮助,您可以使用sendGridMessage.SetBccSetting

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多