ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Email Services in Salesforce with a simple example

Home / Article & Blogs / Salesforce / Email Service / Email Services in Salesforce with a simple example
By Haseeb Khan inEmail Service, Salesforce

email services in salesforce with a simple exampleEmail Services is a feature of salesforce.com where, the user can assign an Apex Class that implements the Messaging.InboundEmailHandler interface to a configuration which allows you to process the email contents, headers and attachments. Using this Information, you can cater a variety of requirements . Listing few, create a new contact if one does not exists with that email address, receive job applications and attached the person’s resume to their record.

Email services are basically an option to a developer to develop a functionality , where an email can be received at a particular address and some operations can happen on the data retrieved from the email. These operations are done by the Apex Code, thus giving us a spectrum of options that fulfils requirements.

Explaining few,

A track of contacts can be kept , once the email is received the contacts are checked for the email address and if not a new contact is created and the attachments in the mail can be added to the new contact record.

In a Human resources management system, All job posting can have a email to it . All the job applications can be received via email and the subject can become the Job title the applicant is applying to. The email service automatically receives the email and creates a job application record using the subject of the email to categorise between job applied for and the resumes can be attached to the job application record as attachments.

Now to start using them,

You can Navigate to Salesforce Email Services using this path : Setup -> Develop -> Email Services,

OR just type Email services in the Quick Find Box.

Click the “New Email Service” button to get started and fill out the form.

The Form has a number of Options, Including Name, Apex Class Etc. Some Options are very handy, “Enable Error Routing” will send the inbound email to an alternative email address when the processing fails. You can can also specify email address to accept mail from.

Note : Make Sure you create a Basic Class that implements the Messaging.InboundEmailHandler interface that can be assign as the class here.

After you save the new email service, you will need to scroll down to the bottom of the page and create a new email address for the service. An email service can have multiple email addresses and therefore process the same message differently for each address. When you create a new email service address you specify the “Context User” and “Accept Email From”. The email service uses the permissions of the Context User when processing the inbound message. So you could, for example, have the same email service that accepts email from US accounts and processes them with a US context user. After the form is submitted the Platform will create a Unique Email Address, To which the email has to be sent. For Example,

test@h-146i8zqbmxebmwfhxj8mdwp1kt96y38ko1b2a9x5rsxea0w8mh.9-10wvleae.ap1.apex.salesforce.com .

Now that we are done with configuring the Email Services, We can move to write the Apex Class as per Requirements.

Scenario :  Create a Contact using the Information in the email and add attachments.

[sourcecode language=”java”]
global class EmailService implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
list<Attachment>att = new list<Attachment>();
Contact con = new contact();
if(email.fromname!=null||email.fromname!=”){
con.FirstName = email.fromname.substring(0, email.fromname.indexOf(‘ ‘));
con.LastName = email.fromname.substring(email.fromname.indexOf(‘ ‘));
}
con.email = envelope.fromaddress;
if(email.plaintextbody!=null||email.plaintextbody!=”)
con.description = email.plaintextbody;
if(email.subject!=null||email.subject!=”)
con.title = email.subject;
insert con;

if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
for (integer i = 0;i<email.binaryAttachments.size();i++) {
Attachment attachment = new Attachment();
attachment.ParentId = con.Id;
attachment.Name = email.binaryAttachments[i].filename;
attachment.Body = email.binaryAttachments[i].body;
att.add(attachment);
}
insert att;
}

if (email.textAttachments != null && email.textAttachments.size() > 0) {
for (integer i = 0; i < email.textAttachments.size(); i++) {
Attachment attachment = new Attachment();
attachment.ParentId = con.Id;
attachment.Name = email.textAttachments[i].filename;
attachment.Body = blob.valueOf(email.textAttachments[i].body);
att.add(attachment);
}
insert att;
}
Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
return result;
}
}
[/sourcecode]

 

Similarly you can have any sort of code in
the apex class, Depends solely on what the 
requirement is. 
Basically the lines of code can use the 
information available and perform some 
operations based on the requirements. 

Happy coding!!!
email services in salesforce
83
Like this post
4 Posts
Haseeb Khan

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Roll-up Summary without a Master Detail Relationship
    Previous PostRoll-up Summary without a Master Detail Relationship
  • Next PostToo Many Verification Code requests on Salesforce login

Related Posts

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Automation in Healthcare And Its Benefits
Health Cloud Salesforce

Automation in Healthcare And Its Benefits

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT