Newer Version Available
Using the InboundEmail Object
For every email the Apex email service domain receives,
Salesforce creates a separate InboundEmail object that contains the contents and
attachments of that email. You can use Apex classes that implement the Messaging.InboundEmailHandler interface to handle
an inbound email message. Using the handleInboundEmail method in that class, you can access an InboundEmail
object to retrieve the contents, headers, and attachments of inbound email messages, as
well as perform many functions.
Example 1: Create Tasks for Contacts
The following is an example of how you can look up a contact based on the inbound email address and create a new task.
Example 2: Handle Unsubscribe Email
Companies that send marketing email to their customers and prospects need to provide a way to let the recipients unsubscribe. The following is an example of how an email service can process unsubscribe requests. The code searches the subject line of inbound email for the word “unsubscribe.” If the word is found, the code finds all contacts and leads that match the From email address and sets the Email Opt Out field (HasOptedOutOfEmail) to True.