Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendGrid "To" List email ids visible to everyone in the list

I am using SendGrid to send emails to a list of users through a console application in asp.net. I am sending a list of user's email addresses in the AddTo section while sending an email. The code looks like this:

SendGridMessage message = new SendGridMessage();
message.AddTo(new List<string>() { "[email protected]", "[email protected]", "[email protected]", "[email protected]" });

The email is sent as expected, but in the "To" section of the email, I am able to see all the email ids of users to whom this email was sent(image attached below). I want the email ids to be hidden so that no one misuses the other email ids in the list. Is there anyway I can accomplish this using SendGrid? enter image description here

like image 301
Sumedha Vangury Avatar asked Sep 13 '25 20:09

Sumedha Vangury


2 Answers

Use .AddBcc() instead of .AddTo(). BUT if you do this then you'll have to set the To address to something like "[email protected]" which isn't ideal and might increase the chances of the message ending up in the SPAM or Junk folders of your users.

SO instead, write a for loop to send the email per user.

var emailAddresses = new List<string>() { "[email protected]", "[email protected]", "[email protected]", "[email protected]" };

for (var emailAddress in emailAddresses)
{
     var email = new SendGridMessage();

     email.AddTo(emailAddress);

     // set other values such as the email contact

     // send/deliver email
}

Is the content of the email message the same for everyone? I would assume each person would have different "monthly usage" amounts and if so the for loop would be better...

like image 113
Justin Steele Avatar answered Sep 15 '25 11:09

Justin Steele


To send to multiple recipients in SendGrid without them seeing each other, you want to use the X-SMTPAPI header, as opposed to the native SMTP To header.

var header = new Header();

var recipients = new List<String> {"[email protected]", "[email protected]", "[email protected]"};
header.SetTo(recipients);

var subs = new List<String> {"A","B","C"};
header.AddSubstitution("%name%", subs);

var mail = new MailMessage
{
    From = new MailAddress("[email protected]"),
    Subject = "Welcome",
    Body = "Hi there %name%"
};

// add the custom header that we built above
mail.Headers.Add("X-SMTPAPI", header.JsonString());

The SMTPAPI header will be parsed by SendGrid, and each recipient will get sent a distinct single-To message.

like image 32
jacobmovingfwd Avatar answered Sep 15 '25 10:09

jacobmovingfwd