0

When ever i am trying to send the emails using single email message method , even the logged in user address getting added to TO list. Is this salesforce default functionality or can we avoid this?

0
  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 ( in this example it is 'testemail@gmail.com').

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
string body = 'Hi '; 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.Address.contains('testuser')) mail.setOrgWideEmailAddressId(owa.id); } mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

Please let us know if this will help you..

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.