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 = '[email protected]'];
 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 Answer 1

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.

1
  • 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, 2019 at 12:39

You must log in to answer this question.

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