If
you want to control the From Email address in salesforce then you can
control this with "Organization-Wide Email Addresses".
An organization-wide email address associates a single email address to a user profile. Each user in the profile can send email using this address. Users will share the same display name and email address
An organization-wide email address associates a single email address to a user profile. Each user in the profile can send email using this address. Users will share the same display name and email address
1. Navigate Setup -> Email Administration -> Organization-Wide Email Addresses
2. Click on Add button.
3.
Enter email Id and display name of sender.
4. In order to complete
this process you need to get verified email id you are putting here
Step
2:- Fetch "Org Wide Email Address" in code like below code.
public class EmailHelper{
public static void sendEmail(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
string body = 'Demo Body ';
String[] toAddresses = new String[] {'abc@gmail.com'}; mail.setToAddresses(toAddresses);
mail.setSubject('Test Subject');
mail.setSaveAsActivity(false);
for(OrgWideEmailAddress owa : [select id, Address, DisplayName from OrgWideEmailAddress]){
if(owa.DisplayName.contains('System Admin')){
mail.setOrgWideEmailAddressId(owa.id);
}
}
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
No comments:
Post a Comment