Email Services in Salesforce
Email Services in Salesforce allow you to automate the processing of inbound emails. You can define an email service that listens for incoming emails, processes them according to your logic, and then takes appropriate actions like creating records, updating records, or triggering workflows
To use email services, from Setup, enter Email Services in the Quick Find box, then select Email Services.
Here are some of the considerations
- An email service only processes messages it receives at one of its addresses.
- Salesforce limits the total number of messages that all email services combined, including On-Demand Email-to-Case, can process daily. Messages that exceed this limit are bounced, discarded, or queued for processing the next day, depending on how you configure the failure response settings for each email service. Salesforce calculates the limit by multiplying the number of user licenses by 1,000; maximum of 1,000,000. For example, if you have 10 licenses, your org can process up to 10,000 email messages a day.
- Email service addresses that you create in your sandbox cannot be copied to your production org.
- For each email service, you can tell Salesforce to send error email messages to a specified address instead of the sender's email address.
- Email services reject email messages and notify the sender if the email (combined body text, body HTML, and attachments) exceeds approximately 25 MB (varies depending on language and character set).
Here are the steps
Here's a simple example of how your Apex class might look:
global class SimpleEmailHandler implements Messaging.InboundEmailHandler {
global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
Messaging.InboundEnvelope envelope) {
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
// Extract necessary information from the email
String subject = email.subject;
String fromAddress = email.fromAddress;
String plainTextBody = email.plainTextBody;
// Here you can add your custom logic based on the email content
// For example, creating a new Lead
Lead newLead = new Lead();
newLead.LastName = 'Web Lead';
newLead.Company = fromAddress;
newLead.Description = plainTextBody;
newLead.Email = fromAddress;
newLead.Status = 'New';
insert newLead;
result.success = true;
return result;
}
}
Associate Email Service with Apex Class:
In your Email Service configuration, select the Apex class you've just created to process inbound emails.
Test Your Email Service:
Send an email to the email address associated with your email service.
Verify that the email is processed according to your Apex class logic.
Check Salesforce to ensure that the desired actions, such as creating a Lead, have been performed.



Comments
Post a Comment