sendgrid / sendgrid-java

The Official Twilio SendGrid Led, Community Driven Java API Library
https://sendgrid.com
MIT License
485 stars 409 forks source link

Unable to hide "to" recipient to see other "to" recipients email with multiple bcc and cc. #686

Closed Ananda2126 closed 3 years ago

Ananda2126 commented 3 years ago

Issue Summary

Unable to hide "to" recipient to see other "to" recipients email with multiple bcc and cc.

Steps to Reproduce

  1. Create Personalization object with multiple to list and multiple bcc and cc
  2. To list email is visible to all recipients.
  3. If we create multiple Personalization objects, its triggering multiple mails to bcc and cc recipients.

Code Snippet

To list email is visible to all recipients:

Mail mail = new Mail();
Email fromEmail = new Email();
fromEmail.setName("TEST");
fromEmail.setEmail("test@test.com");
mail.setFrom(fromEmail);
mail.setSubject("subject");

Personalization personalization = new Personalization();
for(String to: getRecipients().getToEmails()){
    personalization.addTo(new Email(to));
}
for(String bcc: bccList){
    personalization.addBcc(new Email(bcc));
}
for(String cc: ccList){
    personalization.addCc(new Email(cc));
}

mail.addPersonalization(personalization);

Content content = new Content();
content.setType("text/html");
content.setValue("Message Body");
mail.addContent(content);

triggering multiple mails to bcc and cc recipients:

Mail mail = new Mail();
Email fromEmail = new Email();
fromEmail.setName("TEST");
fromEmail.setEmail("test@test.com");
mail.setFrom(fromEmail);
mail.setSubject("subject");

Personalization personalization;
for(String to: getRecipients().getToEmails()){
    personalization = new Personalization();
    personalization.addTo(new Email(to));
    for(String bcc: bccList){
        personalization.addBcc(new Email(bcc));
    }
    for(String cc: ccList){
        personalization.addCc(new Email(cc));
    }
    mail.addPersonalization(personalization);
}

Content content = new Content();
content.setType("text/html");
content.setValue("Message Body");
mail.addContent(content);

Exception/Log

# paste exception/log here

Technical details:

shwetha-manvinkurke commented 3 years ago

@Ananda2126 are you saying that the addresses listed in the Bcc are not hidden from the recipients? Which email client are you using?

Ananda2126 commented 3 years ago

@Ananda2126 are you saying that the addresses listed in the Bcc are not hidden from the recipients? Which email client are you using?

I would like to hide "to" list recipients from seeing others "to" list user email. I am able to achieve this using "X-SMTPAPI" header "to" in V2 api. But with V3 api this header is no more working with Personalization "to" list.

With going through other blogs, they were suggesting to use multiple Personalization. But when I use multiple Personalization with bcc and cc, it trigger duplicate mail to bcc and cc recipients. You can refer code snippet.

And also I tried setting bcc and cc recipients to 1st Personalization object, so that it will not trigger duplicate mail to bcc and cc user. But bcc and cc is not available for mails other than the 1st Personalization mail.

Code Snippet

Mail mail = new Mail(); Email fromEmail = new Email(); fromEmail.setName("TEST"); fromEmail.setEmail("test@test.com"); mail.setFrom(fromEmail); mail.setSubject("subject");

Personalization personalization; for(String to: getRecipients().getToEmails()){ personalization = new Personalization(); personalization.addTo(new Email(to));
mail.addPersonalization(personalization); }

for(String bcc: bccList){ mail.getPersonalization().get(0).addBcc(new Email(bcc)); } for(String cc: ccList){ mail.getPersonalization().get(0).addCc(new Email(cc)); }

mail.addPersonalization(personalization);

Content content = new Content(); content.setType("text/html"); content.setValue("Message Body"); mail.addContent(content);

@reference : https://sendgrid.com/docs/for-developers/sending-email/building-an-x-smtpapi-header/#bcc-with-the-x-smtpapi

shwetha-manvinkurke commented 3 years ago

I'm not too sure I follow. The X-SMTPAPI header is supposed to simulate the Bcc functionality. The addresses specified in Bcc is what will be hidden from non recipients and not the To addresses.

Ananda2126 commented 3 years ago

@shwetha-manvinkurke Please find below references https://sendgrid.com/docs/for-developers/sending-email/building-an-x-smtpapi-header/#bcc-behavior

As per above document, we can simulate "bcc" behavior for "to" list as well and there are 2 ways to achieve this. I was using 2nd option with v2 api and able to achieve this feature. @Reference : https://sendgrid.com/docs/for-developers/sending-email/building-an-x-smtpapi-header/#bcc-with-the-x-smtpapi

But with v3 api personalization "to" list takes priority over x-smtpapi header "to" list.

shwetha-manvinkurke commented 3 years ago

@Ananda2126 Thank you for the clarification. Wasn't aware you could actually do that. In this case, it looks to me like it's a problem with the underlying API itself and not the helper. I would recommend you reach out to support for the resolution.