Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending to multiple Recipients using Sendgrid

I am trying to send a test email using sendgrid to multiple recipients. I used the following as a starting point : https://github.com/sendgrid/sendgrid-google-java

I would all like the users receiving the email also be able to see all the other users on the TO field when they receive the email. Using the mail.addTo API sends the email to all the users however the email is sent individually to all of them (they can't see who all they message went to).

Basically my use case is to send an email to a few users and they should be able to "Reply all" and start communicating with each other. How can I achieve this using appengine/sendgrid/java?

like image 937
user3670859 Avatar asked Dec 25 '22 21:12

user3670859


2 Answers

Something must have changed in the implementation, I'm using sendgrid-java-3.1.0.jar.

My code,

Mail mail = new Mail();
...
Personalization p1 = new Personalization();
p1.addTo(new Email("[email protected]"));
p1.addBcc(new Email("[email protected]"));
mail.addPersonalization(p1);

This appears to work as expected.

like image 130
Neill Avatar answered Jan 04 '23 23:01

Neill


If you want that users could see all list of recipients you can create one personalization for all user list:

var mail = new Mail();
var personalization = new Personalization();
personalization.addTo(new Email([email protected]), name1));
personalization.addTo(new Email([email protected]), name2));
mail.addPersonalization(personalization);

If you want that user could see only themselves - you can specify personalization for each recipient:

var mail = new Mail();
var personalization1 = new Personalization();
personalization1.addTo(new Email([email protected]), name1));
var personalization2 = new Personalization();
personalization2.addTo(new Email([email protected]), name2));
mail.addPersonalization(personalization);
like image 39
Frofike Avatar answered Jan 04 '23 22:01

Frofike