+ Start a Discussion
Jimmy JayJimmy Jay 

Sending Email from Apex and specifying sent from email

We are using Question and Answers in our customer portal and would like email notifications similar to Salesforce Success' question/answer boards.

 

I was able to create a trigger that would send email to the clients involved in the discussion whenever a new reply/answer was added however the only issue I am having is that the email is sent on behalf of the client that posted the reply/answer.

 

In outlook it appears like this:

 

noreply@salesforce.com; on behalf of; Customer Portal <client@clientcompany.com>

 

I do not wish to expose our clients email address to each other, is there a way to send emails from apex code using the same on behalf of every time such as noreply@mycompany.com?

 

Thanks,

Jimmy

Best Answer chosen by Admin (Salesforce Developers) 
Jerun JoseJerun Jose

You can use an Org wide email address to solve this.

 

In apex you can use the method mailObj.setOrgWideEmailAddressID(orgWideAddressRecordID)

All Answers

sfdcfoxsfdcfox
You can specify an Organization-Wide Email Address (Setup > Administration Setup > Email > Organization-Wide Addresses) that you can send from. Users with permission to access this email address can send emails using this from address, and their actual email should be masked as a result.

Salesforce.com uses the "on-behalf' email header to reduce the likelihood of email bounces, spam flags, and/or failed deliveries due to SPF, DKIM, or DomainKeys checks; since the emails are sent from a salesforce.com IP address, using noreply@salesforce.com as the proxy sender reduces the spam flag score.
Jerun JoseJerun Jose

You can use an Org wide email address to solve this.

 

In apex you can use the method mailObj.setOrgWideEmailAddressID(orgWideAddressRecordID)

This was selected as the best answer
Jimmy JayJimmy Jay

Thank you Jerun, that appears to have worked.

 

It looks like I will have to give the portal profile access to the org wide address, is there any thing I should be concerned about when doing this?

 

If the portal user doesn't have access to the org wide address they receive this:

INSUFFICIENT_ACCESS_OR_READONLY, Not profiled to access this Org-wide Email Address

and are unable to post a reply.

Jerun JoseJerun Jose
The only other area that you should be aware of is that, by giving access to a profile for an org wide address, you are now allowing those users to be able to send emails from the application as well. These users can now use the Send Email button of the activities section to send emails using this email address.