I am trying to send a mass email to list of contacts from the apex. SingleEmailMessage has the option to set OrgWideEmailAddress but I don't see an option in MassEmailMessage.

Below is the code to set from email address in SingleEmailMessage.

 OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'doNotReply@blahblah.com'];
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    if ( owea.size() > 0 ) {

How to set from email address in MassEmailMessage.

 List<contact> lstcon=[Select Id,Name,Email,RecordTypeId,RecordType.Name From Contact where RecordType.Name = 'OrgHead'];
 List<Id> lstids= new List<Id>();
 for(Contact c:lstcon)
 EmailTemplate et=[Select id,subject,body from EmailTemplate where name = 'CTemplate' limit 1];

 Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
 Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });

We cannot set From Email when using Mass Email or MassEmailMessage.

Workaround from Knowledge Article:

User can change the email name on their My Email Settings before sending the mass email.


Click Your Name | My Settings | Click on Email on the left | On My Email Settings you will see on right two boxes, you can change as below:

              How would you like your name to appear on your outgoing email? 
             *Email Name

              What email address would you like to use as your return address? 
             *Email Address 

Change and Save.

Note: The personal email associated with your salesforce account will not change.

Here is a link to the existing idea on Ideaexchange:


|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.