We have a daily scheduled apex job that sends email everyday (we use visuaforce email template). I would like to change "From" email address in one specific visulaforce template. I have already added this email address as Organization Wide address. How can I change "From" email for this template.
1 Answer
Once you have created an org-wide address grab the Id from the URL and use the setOrgWideEmailAddressId(Id) method on your instance of Messaging.SingleEmailMessage.
OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = '[email protected]'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
if ( owea.size() > 0 ) {
mail.setOrgWideEmailAddressId(owea.get(0).Id);
}