1

When using Messaging.SingleEmailMessage to send emails to multiple recipients the individual email recipient is able to see the email address of everyone on the sender list.

List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();

    for (Id key : toAddresses.keySet()) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    
      mail.setSenderDisplayName(requestList[0].senderDisplayName);
      mail.setToAddresses(new List<Id>(toAddresses.keySet()));
      mail.setPlainTextBody(requestList[0].body);
      mail.setSubject(requestList[0].subject);
      emails.add(mail);
      
    }

    Messaging.sendEmail(emails, false);

From what I have read in the documentation, it is not possible to use Messaging.MassEmailMessage due to the email content being populated dynamically in a screen flow and not a template. The email is will often be sent to 100+ recipients. Breaking this up into a batch job of size 10 and then calling Messaging.sendEmail for each SingleEmailMessage is a potential solution but seems inefficient. Is there a better way to send emails to multiple recipients without displaying all email addresses from the send list in the received email?

2 Answers 2

1

The documentation is confusing on this topic, which is probably why you're asking this question. You are limited to ten calls of Messaging.sendEmail, not ten emails per call of Messsaging.sendEmail. You may also have seen the 100 recipients limit in the documentation; that only applies to a single Messaging.SingleEmailMessage, not over the entire call; you can easily email thousands of recipients in thousands of different rendered emails at once.

You are free to send as many emails as you want in the first parameter of Messaging.sendEmail (I've tested this up to 1000), provided you don't run in to other limits (daily Apex email limit, DML row limit, SOQL query/row limit, CPU limit, or heap limit). As long as you can construct all the emails within the other limits, you can send all those emails synchronously. This means that you can theoretically send at least 10,000 emails in a single Apex transaction, assuming no other rules are broken. Notably, the daily email limit only applies to leads and contacts, not users.

1
  • Yeah I found the documentation to be confusing. I wasn't sure about the most efficient way of solving this without hitting limits. Thanks for the clarification!
    – Jordan
    Commented Nov 21, 2021 at 15:13
0

In normal emails, you'd put the additional addresses into the BCC field (Blind Carbon Copy) if you don't want people to see the recipients (the ones included in the BCC, that is).

The SingleEmailMessage class does provide a setBccAddresses() method, so it sounds like you want to use that instead of setToAddresses()

1
  • Yeah bcc was also my initial thought but from my understanding, this also comes with a limit of 150 per SingleEmailMessage.
    – Jordan
    Commented Nov 21, 2021 at 15:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .