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 ) { 

​​​​​​​ 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. 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 '19 at 12:39

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.