30
DecChristmas Special : Upto 40% OFF! + 2 free courses - SCHEDULE CALL
Email services are automating the messaging process in salesforce that offers secure and robust functionality to send emails from the Salesforce. In this Salesforce Email Tutorial, we will discuss email services in Salesforce, Salesforce inbound email handler, Salesforce email integration, inbound email service in salesforce, and outbound email service in Salesforce.
Email messages are a more robust and powerful message exchange scheme in Salesforce. When you have to send or receive some email from external systems then we can use email services in Salesforce. There are two most common types of Salesforce email services as given below and we will discuss each of them in detail in future sections.
Moving ahead, let us discuss what is inbound email service in Salesforce.
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 Salesforce email services create an Inbound Email object that contains the contents and attachments of that email. You can use Apex classes to implement the Messaging, Inbound Email Handler Salesforceinterface to handle an inbound Salesforce email message. You can access an Inbound Salesforce Email object to retrieve the contents, headers, and attachments of inbound email messages, as well as perform many functions.
Moving ahead, let us discuss the main methods and properties in Inbound Salesforce Email.
Learn Salesforce in the Easiest Way
Here is a complete list of methods used in inbound Salesforce Email.
This object of this class store the information of the envelope (From address and to address) associated with inbound email.
Read: Zoho vs. Salesforce - CRM Software Comparison for Small Business
The Inbound Email Result used to return the result of the email service. To access email services in Salesforce we need to activate email service
Navigation Setup ->Build->Develop -> Email Services->New Email service
Click on save 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.
Salesforce Training For Administrators & Developers
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;
}
}
Now go to case object
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
Read: A Guide on How to Get & Reset Security Token in Salesforce Lightning
Salesforce Training For Administrators & Developers
With these simple steps, it is easy to create a salesforce inbound email handler. Moving ahead let us discuss what is outbound email service in salesforce.
Outbound email services are used to send an email to the external system using the Apex code. There are two types of outbound email services in salesforce. These are single email messaging and mass email messaging. As the name suggests, a single email message service is used to send a single email and mass email message service is used to send multiple email messages together.
Here is the syntax for single email messaging in salesforce:
Here is the syntax for mass email messaging in salesforce:
Read: Easy Tips to Clear Salesforce Admin Exam in Just One Attempt
Salesforce has a limit on the number of email messages that you can process in the whole day. If this limit exceeds then the remaining message will jump to the next day for processing automatically. The execution depends on how you configure the failure response setting for each email message either inbound or outbound. Salesforce email limits are calculated by multiplying the total number of licenses to 1000 up to a daily maximum limit of 1,000,000.
When you are sure of Salesforce email limits, let us discuss how to create email services in salesforce.
To use email services, go to the setup option then email services option.
Once the email service is created, create an email address for the service from the bottom of the page. An email service can have multiple email addresses attached to it as needed.
This blog for Salesforce Email Integration gives you a sound idea of inbound email services in Salesforce. Here is one detailed example too for your reference to know about Salesforce email limits and Salesforce email services in detail. If you are still confused, signup for our Salesforce training classes online right away and start a never-ending career journey in the IT space.
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.
Cyber Security
QA
Salesforce
Business Analyst
MS SQL Server
Data Science
DevOps
Hadoop
Python
Artificial Intelligence
Machine Learning
Tableau
Search Posts
Related Posts
Salesforce Business Analyst Career Path: Launch Your Rewarding Salesforce Journey 221.2k
Salesforce Admin Resume Examples: Land Your Dream Job 924
What is Salesforce Architecture? Tutorial Guide for Beginners in 2020 467.4k
Salesforce Admin Certification Exam Guide-How to pass it? 255k
Salesforce Developer Salary in the USA| Updated Guide for 2021 262.6k
Receive Latest Materials and Offers on Salesforce Course
Interviews