14 Mar Inbound Email Handler in Salesforce
We all write Workflows or triggers to send email from Salesforce but
Email Service is an apex class which implements interface. This interface enables you to read the Subject,Content,headers and attachment of the incoming email. You read the email in the Email service class and perform DML operations such as creating new records or updated the existing ones as per your requirement.
To create Email services click Setup–> Develop–> Email Services and then create a apex class using the sample code mentioned on the email services landing page. See the snapshot below :
Once the class is create go ahead and click on New Email Service button enter the information as displayed in the image below, Change the Error routing address from email@example.com to your email address so that you receive error notifications when the email processing fails.
Click on “Save and New email Address” , Once done choose the context user and keep the Accept email from field blank to accept emails from all kind of domains. Clicking on Save will generate a email address automatically ,this email address will look somewhat like
Now we can write the logic which is to be executes when an email is sent to the above created email address. Copy the below code and replace it in the email service class created initially in the post. (myHandler )