function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Steve BerleySteve Berley 

email.setOrgWideEmailAddressId() causes messages to go to spam

I have code which sends emails where i'm trying to control the sending email address.

I'm finding if I set an org wide email address, using setOrgWideEmailAddressId(), messages always go to spam.  If I don't set it they avoid spam but don't come from the desired sender.

Anyone have suggestions of how to control the sender and stay out of spam?

Thanks,

Steve 
SwethaSwetha (Salesforce Developers) 
HI Steve,
You might want to set up an SPF record (Sender Policy Framework) on your own domain (the orgwideemail address, which is your company domain).
When you create an SPF entry against your DNS, you are effectively telling recipients that the named sender (in this case salesforce) is allowed to send mails on behalf of your domain (orgwideemail).

Reference: https://salesforce.stackexchange.com/questions/13131/avoid-blacklisting-of-org-wide-email-address

Also check https://developer.salesforce.com/forums/?id=906F0000000D8enIAC

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you