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: How To Start Your Career In Salesforce?

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: Queueable Apex Job

Apex class
global Class InboundEmailEx implements Messaging.InboundEmailHandler {
publicMessaging.InboundEmailResulthandleInboundEmail
           (Messaging.InboundEmailemail,Messaging.InboundEnvelopeenv){  
Messaging.InboundEmailResult res= new Messaging.InboundEmailResult();
try{
case c= new case();
c.subject= email.subject;
c.Priority='High';
c.Origin='Email';
c.Status='new';
c.Description= email.plainTextBody;
stringemailadd= email.fromAddress;
contact con=[select id from contact where email=:emailadd limit 1];
c.ContactId=con.id;
insert c;
res.success=true;
        }
catch(Exception e){
res.success=false;
     }           
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.InboundEmailHandler{
globalMessaging.InboundEmailResulthandleInboundEmail
(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 Developer Salary in the USA- Things You Need to Know

Salesforce Tutorial Overview


    Janbask Training

    JanBask Training is a leading Global Online Training Provider through Live Sessions. The Live classes provide a blended approach of hands on experience along with theoretical knowledge which is driven by certified professionals.


Trending Courses

AWS

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

Upcoming Class

4 days 24 Nov 2019

DevOps

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

Upcoming Class

5 days 25 Nov 2019

Data Science

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

Upcoming Class

5 days 25 Nov 2019

Hadoop

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

Upcoming Class

6 days 26 Nov 2019

Salesforce

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

Upcoming Class

-1 day 19 Nov 2019

Course for testing

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

Upcoming Class

34 days 24 Dec 2019

QA

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

Upcoming Class

13 days 03 Dec 2019

Business Analyst

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

Upcoming Class

5 days 25 Nov 2019

SQL Server

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

Upcoming Class

-1 day 19 Nov 2019

Comments

Search Posts

Reset

Receive Latest Materials and Offers on Salesforce Course

Interviews