【问题标题】:SendGrid "To" List email ids visible to everyone in the listSendGrid“收件人”列表电子邮件 ID 对列表中的每个人都可见
【发布时间】:2015-12-12 05:53:48
【问题描述】:

我正在使用 SendGrid 通过 asp.net 中的控制台应用程序向用户列表发送电子邮件。我在发送电子邮件时在 AddTo 部分发送用户电子邮件地址列表。代码如下所示:

SendGridMessage message = new SendGridMessage();
message.AddTo(new List<string>() { "user1@abc.com", "user2@xyz.com", "user3@abc.com", "user4@xyz.com" });

电子邮件按预期发送,但在电子邮件的“收件人”部分,我可以看到收到此电子邮件的用户的所有电子邮件 ID(图片附在下面)。我希望隐藏电子邮件 ID,以免有人滥用列表中的其他电子邮件 ID。无论如何我可以使用 SendGrid 完成此操作吗?

【问题讨论】:

    标签: c# asp.net console-application email sendgrid


    【解决方案1】:

    使用 .AddBcc() 而不是 .AddTo()。但是,如果您这样做,则必须将“收件人”地址设置为“no-reply@example.com”之类的东西,这并不理想,并且可能会增加邮件最终出现在您的垃圾邮件或垃圾文件夹中的机会用户。

    因此,请编写一个 for 循环来为每个用户发送电子邮件。

    var emailAddresses = new List<string>() { "user1@abc.com", "user2@xyz.com", "user3@abc.com", "user4@xyz.com" };
    
    for (var emailAddress in emailAddresses)
    {
         var email = new SendGridMessage();
    
         email.AddTo(emailAddress);
    
         // set other values such as the email contact
    
         // send/deliver email
    }
    

    每个人的电子邮件内容都相同吗?我会假设每个人会有不同的“每月使用量”数量,如果是这样,for 循环会更好......

    【讨论】:

      【解决方案2】:

      要在 SendGrid 中发送给多个收件人而不让他们看到对方,您需要使用 X-SMTPAPI header,而不是使用本机 SMTP To 标头。

      var header = new Header();
      
      var recipients = new List<String> {"a@example.com", "b@exampe.com", "c@example.com"};
      header.SetTo(recipients);
      
      var subs = new List<String> {"A","B","C"};
      header.AddSubstitution("%name%", subs);
      
      var mail = new MailMessage
      {
          From = new MailAddress("please-reply@example.com"),
          Subject = "Welcome",
          Body = "Hi there %name%"
      };
      
      // add the custom header that we built above
      mail.Headers.Add("X-SMTPAPI", header.JsonString());
      

      SendGrid 将解析 SMTPAPI 标头,每个收件人将收到一条不同的单到消息。

      【讨论】:

      • 如果使用 SmtpClient 和 MailMessage 类,这将适用。 OP 正在使用 SendGridMessage。如果 OP 将他的代码更改为使用 SmtpClient 和 MailMessage 类,那么这将起作用。
      猜你喜欢
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      相关资源
      最近更新 更多