Apex Email Service
- johnsontitus
- May 8, 2020
- 1 min read
Use Case:
When an email is received from a client, a task should be created against the contact record with the email matching the 'from address'.
Solution:
Use Apex Email service.
You can associate each email service with one or more Salesforce-generated email addresses to which users can send messages for processing.
To use email services, from Setup, enter Email Services in the Quick Findbox, then select Email Services.
Choose the Apex class you want this email service to use to process messages. The Apex class you choose must implement theMessaging.InboundEmailHandlerinterface.
After you save the new email service, you will need to scroll down to the bottom of the page and create a new email address for the service. An email service can have multiple email addresses and therefore process the same message differently for each address. When you create a new email service address you specify the "Context User" and "Accept Email From". The email service uses the permissions of the Context User when processing the inbound message. So you could, for example, have the same email service that accepts email from US accounts and processes them with a US context user and another address that accepts email from EMEA accounts and processes them with an EMEA context user. After you submit them the Force.com platform will create a unique email address like the following. This is the address you send your email to for processing.
Note:
To test this out, you can send an email to the above address from an email application - gmail (depending on the configuration set whilst defining the email service)

Comments