1

How do we set From Address while sending email using messaging.SingleEmailMessage. I have got a solution which uses setOrgWideEmailAddressId to set from address,

    OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress where Address = 'doNotReply@blahblah.com'];
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 if ( owea.size() > 0 ) { 
mail.setOrgWideEmailAddressId(owea.get(0).Id); 
}

​​​​​​​ But I want to query the record ( say the contact who logged in ) and set that as From Address.

Can Anyone help me out with this?

1
  1. When you don't set any address in setOrgWideEmailAddressId method SingleEmailMessage will automatically send email from logged in users email id.
  2. Alternatively you can add any org wide email from setOrgWideEmailAddressId method.

You cannot use any other email apart from these two, because by that way you will be able to set anyone's email in from address.

  • Your Response helped me. I have got a solution for it. I will Query the logged in user and assign it to Display Name. That is what I actually wanted. – Salman Feb 11 at 12:39

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.