
Email Services in Salesforce | The Developer Guide
Email Service
Email services are computerizing the informing procedure in Salesforce that offers secure and strong usefulness to send messages from Salesforce. In this Salesforce Email Tutorial, we will talk about email benefits in Salesforce, Salesforce inbound email handler, Salesforce email reconciliation, inbound email administration in salesforce, and outbound email administration in Salesforce. Email services only process its messages it receives one of its addresses.
The general interface to create the apex class for the email services is:
global class myHandler implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); return result; } }
Don't forget to check out: Insert Record by Email Service Attachments in Salesforce
Methods in Inbound Salesforce Email
Here is a list of methods used in inbound Salesforce Email.
- CC Addresses
- From Address
- From Name
- Headers
- HTML Body
- HTML Body Is Truncated
- In Reply To
- Message-Id:
- Plain Text Body:
- Plain Text Body Is Truncated:
- Reply To:
- Subject: The subject line of the email, if any.
- Text Attachments:
- To Addresses:
Steps for Configure inbound email services in Salesforce
Step 1. Login into your org Account
Step 2. Go to Setup, enter Email Service in the Quick Find box
Step 3. New Email service.
Step 4. For Apex Class, specify the Apex class you just built
Step 5. Define the attachment type.
Step 6. Mention from where we want to receive an email.
Step 7. Select active.
Step 8. You can leave the rest of the fields at their default values for starters
Step 9. Click on save.
You can relate each email administration with at least one Salesforce-produced email delivered to which clients can send messages for handling.
Here is an example for Email Service
Here's a simple class that creates a new contact and attaches any documents to the record.
Check out another amazing blog by Ayush here: Types of Collections in Apex Salesforce | Explained
Creating Contact from email
/** // Email services are self-operating processes that use Apex class * to procedure the contents, headers, and attachments of inbound * email. */ global class CreateContactFrmEmail implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { // Create an InboundEmailResult object // Create email Apex Email Service Class Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); String S1= 'Create Contact'; if(email.subject.equalsIgnoreCase(S1)){ // setup the data for the email Contact c = new Contact(); c.LastName = email.plainTextBody; insert c; // Save attachments, if any for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) { // attach to the newly created record Attachment atcm= new Attachment(); atcm.Name = tAttachment.fileName; atcm.Body = Blob.valueOf(tAttachment.body); atcm.ParentId = c.Id; insert atcm; } result.success = true; return result; } } }
After completing the above steps, An email address is generated by the Salesforce. Send the email to that address with the subject and contact name in the email body.
- Salesforce calculates the restriction by multiplying the number of user licenses via 1,000, up to a daily maximum of one million.
- Email address created in the sandbox or not in production org.
- An Email service processed only that message that are received for its address
- Email service uses Apex class to process inbound email.
Reference: jitendrazaa, blog.jeffdouglas
Responses