1

In this what I will for Set a Default From Email Address.

 Messaging.SingleEmailMessage EmailMessage = new Messaging.SingleEmailMessage();
 EmailMessage.setTargetObjectId(opp.Applicant_Student_Record__c);
 EmailMessage.setTemplateId(et.Id);
 EmailMessage.setWhatId(opp.Id);
 EmailMessage.setSaveAsActivity(false);
 EmailMessage.setReplyTo('[email protected]');
 EmailMessage.setSenderDisplayName('Development');
 EmailMessage.setFileAttachments(Attachment);
 emails.add(EmailMessage);  
0

1 Answer 1

3

To do this you must first set up a dedicated email address by navigating to Setup -> Administration Setup -> Email Administration -> Organization-Wide Addresses menu.

Setup the address(say :[email protected]) and need to verify for the use.

enter image description here

Add the below code :

OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = '[email protected]'];
Messaging.SingleEmailMessage EmailMessage = new Messaging.SingleEmailMessage(); 
if ( owea.size() > 0 ) {
    EmailMessage.setOrgWideEmailAddressId(owea.get(0).Id);
}
EmailMessage.setTargetObjectId(opp.Applicant_Student_Record__c); 
EmailMessage.setTemplateId(et.Id); 
EmailMessage.setWhatId(opp.Id); 
EmailMessage.setSaveAsActivity(false); 
EmailMessage.setReplyTo('[email protected]'); 
EmailMessage.setSenderDisplayName('Development'); 
EmailMessage.setFileAttachments(Attachment);
emails.add(EmailMessage);

Here setting up the email address at "Email Administration" will help you to set the desired mail address from whom you want to send the mail( form which you are also querying from "OrgWideEmailAddress" to get the particular one if in case you have multiple address setup).

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