Innovate anywhere, anytime Your cloud-based dev studio.

Inbound Email Service for Creating Records in Salesforce


Email Services in salesforce are automated processes that use apex classes to process details or content in the Email. When you have to send or receive some email from external systems then we can use email services in Salesforce. There are two types of Email Services in salesforce. They are Inbound Email Services and Outbound Email Services(already discussed in one of our blogs).

Inbound Email Services:

Emails received from external systems to salesforce use apex class to retrieve details and attachments in the email. Apex classes use the InboundEmail object to process the email.For example, we can create an email service that automatically creates account records based on the account information received in the Inbound Email.

How to Create Inbound Email Service:

Click on Setup--> Build--> Develop--> Email Services

Before creating Email Services, Create Apex classes that implement the Messaging.InboundEmailhandler interface. 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.

Apart from Messaging.InboundEmailhandler, there are some predefined classes under Messaging Namespace.

InboundEmail.Header Object

InboundEmail.BinaryAttachment Object

InboundEmail.TextAttachment Object

InboundEmailResult Object

InboundEnvelope Object

After Creating Apex Classes based on requirement, Create an Email Service:

  1. Click on New Email Service, Enter Email Service name
  2. Choose the appropriate class which you created earlier. Choose the type of attachments you want to accept.
  3. Click on the Advanced Email Security settings checkbox.

Note: Before enabling this option, make sure that your users’ email domains support at least one of the following protocols: SPF, Sender ID, or DomainKeys. When this option is enabled, uses these protocols to verify the legitimacy of the email sender's server. If the server passes at least one protocol and does not fail any, processes the email. If the server fails a protocol or does not support any of the protocols, then does not process the email.

  1. Optionally, List the email addresses and domains from which you want this email service to receive emails. Separate multiple entries by commas. Leave this field blank if you want the email service to receive email from any email address or domain.
  2. Choose whether to convert text attachments to binary attachments and active checkbox.
  3. Configure Failure response settings and click on save.