---
schema_version: "1"
id: 8b185708d026301ac7b7cf36b498d3d14d2f48ff3c78bb2cda69cadcaf069c24
title: Define Email Services
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/code_email_services_editing.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.code_email_services_editing.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 72626b41dd6a3653d94773d681c91a23d66685a2e444c482a9638334e998ba09
description: Set up an email service to handle incoming email, and configure the service to process messages according to your users' needs.
products:
  - Salesforce Platform
release: "264"
---
# Define Email Services

Set up an email service to handle incoming email, and configure the service to process messages according to your users' needs.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
        <colgroup>
          <col>
        </colgroup>
        <tbody>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic (<a href="https://help.salesforce.com/s/articleView?id=xcloud.overview_edition_lex_only.htm&amp;type=5&amp;language=en_US" target="_blank">not available
                in all orgs</a>) and Lightning Experience</td>

          </tr>
          <tr class="">
            <td class="slds-cell-wrap" style="vertical-align:top;">
              <p>Available in: <strong>Enterprise</strong>, <strong>Performance</strong>,
                <strong>Unlimited</strong>, and <strong>Developer</strong> Editions
              </p>
              <p style="margin-bottom:0;">Use of email
                services in installed AppExchange packages also available in:
                <strong>Essentials</strong>, <strong>Group</strong>, and <strong>Professional</strong>
                Editions
              </p>
            </td>

          </tr>
        </tbody>
      </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
        <colgroup>
          <col style="width:50%">
          <col style="width:50%">
        </colgroup>
        <thead class="slds-text-title_caps ">
          <tr class="">
            <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d6683e87">User
              Permissions Needed</th>
          </tr>
        </thead>
        <tbody>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d6683e87 ">To configure Apex email services and email service
              addresses:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d6683e87 ">Customize Application</td>

          </tr>
          <tr class="">
            <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d6683e87 ">To create Apex classes:</td>

            <td class="slds-cell-wrap" style="vertical-align:top;" headers="d6683e87 ">Author Apex</td>

          </tr>
        </tbody>
      </table>

1. From Setup, enter Email Services in the Quick Find box, then select **Email Services**.
2. Click **New Email Service**, or click **Edit** to change an existing email service.
3. Specify the name of the email service.
4. Choose the Apex class you want this email service to use to process messages.
    
    The Apex class you choose must implement the `Messaging.InboundEmailHandler` interface. For example:
    
    ```java
    global class myHandler implements Messaging.InboundEmailHandler {
                global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
                    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
                    return result;
                }
            }
    ```
    
    For information on the InboundEmail object, see [Using the InboundEmail Object](https://help.salesforce.com/s/articleView?id=platform.code_inbound_email.htm&release=264.0.0&type=5 "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.").
5. Choose the types of attachments you want the email service to accept. The options are:
    
    <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small ">
            <colgroup>
              <col style="width:21.83406113537118%">
              <col style="width:78.16593886462883%">
            </colgroup>
            <tbody>
              <tr class="">
                <td class="slds-cell-wrap" style="vertical-align:top;">None</td>

                <td class="slds-cell-wrap" style="vertical-align:top;">The email service accepts the message but discards any
                  attachment.</td>

              </tr>
              <tr class="">
                <td class="slds-cell-wrap" style="vertical-align:top;">Text Attachments Only</td>

                <td class="slds-cell-wrap" style="vertical-align:top;">
                  <p>The email service only accepts the following types of
                    attachments: </p>
                  <ul>
                    <li>Attachments with a Multipurpose Internet Mail
                      Extension (MIME) type of <code>text</code>.</li>
                    <li>Attachments with a MIME type of <code>application/octet-stream</code> and a file name
                      that ends with either a <samp class="filepath">.vcf</samp> or
                      <samp class="filepath">.vcs</samp> extension. These
                      attachments are saved as <code>text/x-vcard</code> and
                      <code>text/calendar</code> MIME types,
                      respectively.
                    </li>
                  </ul>
                  <p style="margin-bottom:0;">Messages with attachments other than these types are
                    accepted, but the attachments are discarded.</p>
                </td>

              </tr>
              <tr class="">
                <td class="slds-cell-wrap" style="vertical-align:top;">Binary Attachments Only</td>

                <td class="slds-cell-wrap" style="vertical-align:top;">
                  <p>The email service only accepts binary attachments, such
                    as image, audio, application, and video files. Binary
                    attachments have a limit of 5 MB per attachment. </p>
                  <p style="margin-bottom:0;">Messages
                    with attachments that aren’t binary are accepted, but
                    the attachments are discarded.</p>
                </td>

              </tr>
              <tr class="">
                <td class="slds-cell-wrap" style="vertical-align:top;">All</td>

                <td class="slds-cell-wrap" style="vertical-align:top;">The email service accepts any type of attachment.</td>

              </tr>
            </tbody>
          </table>
    
    An email service can only process attachments if you configure the email service to accept attachments and use an Apex class that processes the types of attachments the email service accepts.
    
    Email services can’t accept inline attachments, such as graphics inserted in email messages.
6. Optionally, select the **Advanced Email Security Settings** checkbox to configure the email service to verify the legitimacy of the sending server before processing a message. The email service uses the following authentication protocols to verify the sender's legitimacy:If Advanced Security permission is disabled in your org, Advanced Email Settings aren't available.
    
    - DKIM
    - DMARC
    - SPF
    
    If the sending server passes at least one of these protocols and doesn’t fail any, the email service accepts the email. If the server fails a protocol or doesn’t support any of the protocols, the email service performs the action specified in the Unauthenticated Sender Action failure response setting. Two exceptions apply.
    
    - If DMARC passes and SPF fails, the email service accepts the email.
    - If DKIM fails and any other protocol passes, the email service accepts the email.
    
    If Advanced Security permission is disabled in your org, Advanced Email Settings aren't available. Before selecting the **Authenticate Senders** checkbox, ensure that the senders that you expect to use the email service support at least one of the authentication protocols listed. For information on these authentication protocols, see the following websites:
    
    - [https://dkim.org/](https://dkim.org/)
    - [https://dmarc.org/](https://dmarc.org/)
    - [www.open-spf.org](http://www.open-spf.org/)
7. Email services reject email messages and notify the sender if the email exceeds approximately 25 MB (combined body text, body HTML, and attachments). This size varies depending on language and character set.
8. You can convert text attachments to binary attachments.
9. Optionally, configure this email service only to accept messages from certain senders by listing their email addresses and domains in the **Accept Email From** text box. Separate multiple entries with commas. For example: george@mycompany.com, yahoo.com, gmail.com. If the **Accept Email From** text box has a value and the email service receives a message from an unlisted email address or domain, the email service performs the action specified in the Unauthorized Sender Action failure response setting.
    
    Leave this field blank if you want the email service to receive email from any email address.
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_note.png)
    
    Note You can also authorize email addresses and domains at the email service address-level. See [Defining Email Service Addresses](https://help.salesforce.com/s/articleView?id=platform.code_email_service_address.htm&release=264.0.0&type=5 "Add an inbound email address for an email service.").
    
    If both the email service and email service address are configured to accept messages only from certain senders, the email service processes messages only from senders that are listed in the **Accept Email From** text boxes on both the email service and the email service address.
10. Select the **Active** checkbox if you want the email service to be activated when you click **Save**.
11. Configure the failure response settings, which determine how the email service responds if an attempt to access this email service fails for the following reasons:The failure response options are:
    
    <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small "><colgroup><col style="width:23.474178403755868%"> <col style="width:76.52582159624413%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Over Email Rate Limit Action</td><td class="slds-cell-wrap" style="vertical-align:top;">Determines what the email service does with messages if the total number of messages processed by all email services combined has reached the daily limit for your organization. Salesforce calculates the limit by multiplying the number of user licenses by 1,000; maximum 1,000,000. For example, if you have 10 licenses, your org can process up to 10,000 email messages a day.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Deactivated Email Address Action</td><td class="slds-cell-wrap" style="vertical-align:top;">Determines what the email service does with messages received at an email address that is inactive.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Deactivated Email Service Action</td><td class="slds-cell-wrap" style="vertical-align:top;">Determines what the email service does with messages it receives when the email service itself is inactive.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Unauthenticated Sender Action</td><td class="slds-cell-wrap" style="vertical-align:top;">Determines what the email service does with messages that fail or don’t support any of the authentication protocols if the <strong class="uicontrol">Authenticate Senders</strong> checkbox is selected.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Unauthorized Sender Action</td><td class="slds-cell-wrap" style="vertical-align:top;">Determines what the email service does with messages received from senders who aren’t listed in the <strong class="uicontrol">Accept From Email</strong> text box on either the email service or email service address.</td></tr></tbody></table>
    
    The failure response options are:
    
    <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small "><colgroup><col style="width:42.5531914893617%"> <col style="width:57.446808510638306%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Bounce Message</td><td class="slds-cell-wrap" style="vertical-align:top;">The email service returns the message to the sender or to the Automated Case User for On-Demand Email-to-Case, with a notification that explains why the message was rejected.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Discard Message</td><td class="slds-cell-wrap" style="vertical-align:top;">The email service deletes the message without notifying the sender.</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Requeue Message (<strong class="uicontrol">Over Email Rate Limit Action</strong> Only)</td><td class="slds-cell-wrap" style="vertical-align:top;">The email service queues the message for processing in the next 24 hours. If the message isn’t processed within 24 hours, the email service returns the message to the sender with a notification that explains why the message was rejected.</td></tr></tbody></table>
12. To send error email messages to a specified address instead of the sender's email address, select **Enable Error Routing** and specify the destination email address in **Route Error Emails to This Email Address**. This action prevents the sender being notified when email services can’t process an incoming email.
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_note.png)
    
    Note The Enable Error Routing feature only applies to the following five failure scenarios, and only when "Bounce Message" is selected as the response action:
    
    - Over Email Rate Limit Action
    - Deactivated Email Address Action
    - Deactivated Email Service Action
    - Unauthenticated Sender Action
    - Unauthorized Sender Action
    
    If "Discard Message" or "Requeue Message" is selected for any of these failure responses, error routing does not occur.
13. Click **Save** to save your changes, or **Save and New Email Address** to create email addresses for this email service, as described in [Defining Email Service Addresses](https://help.salesforce.com/s/articleView?id=platform.code_email_service_address.htm&release=264.0.0&type=5 "Add an inbound email address for an email service.").

#### See Also

- [What Are Email Services?](https://help.salesforce.com/s/articleView?id=platform.code_email_services_overview.htm&release=264.0.0&type=5 "Email services are automated processes that use Apex classes to process inbound email.")
- [Define Email Service Addresses](https://help.salesforce.com/s/articleView?id=platform.code_email_service_address.htm&release=264.0.0&type=5 "Add an inbound email address for an email service.")
- [The InboundEmail Object](https://help.salesforce.com/s/articleView?id=platform.code_inbound_email.htm&release=264.0.0&type=5 "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.")
- [Email Services](https://help.salesforce.com/s/articleView?id=platform.code_email_services.htm&release=264.0.0&type=5 "You can use email services to process the contents, headers, and attachments of inbound email. For example, you can create an email service that automatically creates contact records based on contact information in messages.")