Today's Offer - Salesforce Certification Training - Enroll at Flat 10% Off.

- Salesforce Blogs -

What is Inbound Email Service in Salesforce?

What is Inbound Email Service?

You can use Apex to receive and process email and attachments from the external system to Salesforce. The email is received by the Apex email service and processed by Apex classes that utilize the Inbound Email object. Apex email service creates an Inbound Email object that contains the contents and attachments of that email. You can use Apex classes that implement the Messaging. Inbound Email Handler interface to handle an inbound email message. You can access an Inbound Email object to retrieve the contents, headers, and attachments of inbound email messages, as well as perform many functions.

Below are predefined classes

  • Inbound Email Handler
  • Inbound Email Binary Attachments
  • Inbound Email Inbound Envelope
  • Inbound Email Result.

Methods in Inbound Email Properties

  • Binary Attachments

  • A list of binary attachments received with the email if any.
  • CC Addresses

  • A list of carbon copy (CC) addresses if any.

  • From Address

  • The email address that appears in the From field.

  • From Name

  • The name that appears in the From field, if any.

  • Headers

  • A list of the RFC 2822 headers in the emai.
  • HTML Body

  • The HTML version of the email, if specified by the sender.
  • HTML Body Is Truncated

  • Indicates whether the HTML body text is truncated (true) or not (false.)

  • In Reply To

  • The In-Reply-To field of the incoming email. Identifies the email or emails to which this one is a reply (parent emails). Contains the parent email or emails' message-IDs.
  • Message-Id

  • The Message-ID—the incoming email's unique identifier.
  • Plain Text Body

  • The plain text version of the email, if specified by the sender.
  • Plain Text Body Is Truncated

  • Indicates whether the plain body text is truncated (true) or not (false.)
  • Reply To

  • The email address that appears in the reply-to header.
  • Subject

  • The subject line of the email, if any.
  • Text Attachments

  • A list of text attachments received the email if any.
  • To Addresses

  • The email address that appears in the To

salesforce quiz

Read: Salesforce Admin Interview Questions and Answers

Inbound Envelope Properties

The following are properties for Inbound Envelope.

  • From Address The name that appears in the From field of the envelope, if any.
  • To Address The name that appears in the Tofield of the envelope, if any.

Messaging Inbound Envelope:

This object of this class store the information of envelope (From address and to address) associated with inbound email.

Messaging. Inbound Email Result:

The Inbound Email Result used to return the result of email service. To access email services in Salesforce we need to activate email service

Read: What is Salesforce Sandbox? How to Create & Uses of Sandbox?

How to configure Email service

Navigation Setup ->Build->Develop -> Email Services->New Email service What is Inbound Email Service in Salesforce?

  1. Give a name for Email Service Name.
  2. For Apex Class, specify the Apex class you just built
  3. Define attachment type.
  4. Mention from where we want receives email.
  5. Select active.
  6. You can leave the rest of the fields at their default values for starters
  7. Click on save.

What is Inbound Email Service in Salesforce? Click on save What is Inbound Email Service in Salesforce? Any email sent to the above email address will now result in the Apex class being executed. You would typically alias this email address behind one in your own domain.

Read: What Apex Email in Salesforce?

Apex class
global Class InboundEmailEx implements Messaging.InboundEmailHandler {
Messaging.InboundEmailResult res= new Messaging.InboundEmailResult();
case c= new case();
c.subject= email.subject;
c.Description= email.plainTextBody;
stringemailadd= email.fromAddress;
contact con=[select id from contact where email=:emailadd limit 1];;
insert c;
catch(Exception e){
return res;

What is Inbound Email Service in Salesforce? Now go to case object What is Inbound Email Service in Salesforce?

Email Attachment Example
global class AttachmentEmailExample implements 
(Messaging.InboundEmailemail,Messaging.InboundEnvelope envelope)
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
    Contact contact = new Contact();
contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' '));
contact.LastName = email.fromname.substring(email.fromname.indexOf(' '));
contact.Email = envelope.fromAddress;
insert contact;
System.debug(' Created contact '+contact.Id);
if (email.binaryAttachments != null &&email.binaryAttachments.size() > 0) 
for (integer i = 0 ; i<email.binaryAttachments.size() ; i++)
        Attachment attachment = new Attachment();
        // attach to the newly created contact record
attachment.ParentId = contact.Id;
attachment.Name = email.binaryAttachments[i].filename;
attachment.Body = email.binaryAttachments[i].body;
insert attachment;
return result;

Preview What is Inbound Email Service in Salesforce?

Read: Salesforce Security Model- What Do You Need To Know?

Salesforce Tutorial Overview

    Janbask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.

Trending Courses


  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

5 days 02 Feb 2020


  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

-1 day 27 Jan 2020

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

6 days 03 Feb 2020


  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

7 days 04 Feb 2020


  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

0 day 28 Jan 2020


  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

-1 day 27 Jan 2020

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

-1 day 27 Jan 2020

SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

3 days 31 Jan 2020


Search Posts


Receive Latest Materials and Offers on Salesforce Course