Skip to main content
2 of 2
added 285 characters in body

Set a From: address in a salesforce SingleEmailMessage while using an email template

I am sending out an email using SingleEmailMessage. I have an Organization wide email address what I need to use as the From address. However, I am using an email template to generate the body of the email. The method setOrgWideEmailAddressId does not work when the email template is being used. Is there any way around this?

Basically I need to do this:

if ( owea.size() > 0 ) {
     email.setOrgWideEmailAddressId(owea.get(0).Id);
}
    
mail = Messaging.renderStoredEmailTemplate(emailTemplate.Id+'', accountIdContactMap.get(opp.AccountId).Id+'', opp.Id+'');
           

The only thing I can think of is to generate the email in apex with string building.