Email to Flow in Salesforce
Hi Folks!
These days, Email is still the most popular communication tool to interact with each other. And the good news is Salesforce understands about that, and they come up with so many solutions related to email automations like Email Alert, Email Services, Gmail Integration with Salesforce, Gmail Lightning Sync, etc.
All those email automations I mentioned above has different functionality. The one that I want to highlight here is Email Services.
Referred from Salesforce Help site. Email Services are automated processes that use Apex classes to process inbound email. Yes…. Apex class, you’ll need an Apex Class to handle Inbound email and do automation in your Salesforce Org.
But what if…. you can use Flow Builder to handle Email Inbound in your Salesforce org? hmm tempting isn’t it? That’s why in this article, I’d like to show you my generic solution on how I handled Email Inbound with AutoLaunched Flow.
Main functions of my solution are to:
- Route Email from your Email Services to Autolaunched flow (you can route this to any object you want to)
- Pass all variables from inbound email (or email service) to Flow variables
- Convert email attachments to ContentVersion records variable (if your email attachments contain text attachments, it will be converted to pdf in ContentVersion)
- AutoReply to email sender with a HTML text(optional)
Attributes
Input from Email Service to flow
- Envelope_FromAddress
type: Text / String
description: The name that appears in the From field of the envelope, if any. - Envelope_ToAddress
type: Text / String
description: The name that appears in the To field of the envelope, if any. - Email_ToAddresses
type: Text / String (Collection)
description: The email address that appears in the To field. - Email_FromName
type: Text / String
description: The name that appears in the From field, if any. - Email_FromAddress
type: Text / String
description: The email address that appears in the From field. - Email_CCAddresses
type: Text / String (Collection)
description: A list of carbon copy (CC) addresses, if any. - Email_Subject
type: Text / String
description: The subject line of the email, if any. - Email_ReplyTo
type: Text / String
description: The email address that appears in the reply-to header. - Email_MessageId
type: Text / String
description: The Message-ID — the incoming email’s unique identifier. - Email_References
type: Text / String (Collection)
description: The References field of the incoming email. Identifies an email thread. Contains a list of the parent emails’ References and message IDs, and possibly the In-Reply-To fields. - Email_HTMLBody
type: Text / String
description: The HTML version of the email, if specified by the sender. - Email_IsHTMLTruncated
type: Boolean
description: Indicates whether the HTML body text is truncated (true) or not (false) - Email_TextBody
type: Text / String
description: The plain text version of the email, if specified by the sender. - Email_IsTextBodyTruncated
type: Boolean
description: Indicates whether the plain body text is truncated (true) or not (false) - Email_ContentVersion
type: ContentVersion Records (Collection)
description: Collection of converted email attachments (if attachment is text will be converted to pdf)
Output from Flow
- AutoReplyMessage (optional)
type: Text / String
description: define whether the Inbound email needs to be auto replied or not. If null, won’t send autoreply. Support HTML Message
How to setup
Step 1. Install EmailToFlow Package from here
<v.1.1>(support html in autoreply email)
Prod: https://login.salesforce.com/packaging/installPackage.apexp?p0=04tJ1000000olto
Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04tJ1000000olto
<v.1.0 Deprecated>
Prod: https://login.salesforce.com/packaging/installPackage.apexp?p0=04t2w000009F5xV
Sandbox: https://test.salesforce.com/packaging/installPackage.apexp?p0=04t2w000009F5xV
This package includes
1. EmailToFlow class : Router from email service to flow
2. EmailToFlowTest class: Test class for the apex class
3. EmailToFlowController Autolaunched flow: Main flow to control your inbound email
Source code: https://github.com/munawirrahman/EmailToFlow
Step 2. Create a new email address to receive inbound email
Step 3. Test your email
There you go! once you set this up, you can do pretty much anything with this Email to Flow, like Create, Delete, Update records, Logging emailmessage to a record, autoforward the email with additional information from Salesforce, etc. But also remember that, you should have some kind of email inbound contract when using this, in my setup example, the contract is “The email subject should equal to Test Email To Flow” you can create your own contract based on your business requirements.
Thank you for reading, clap if you think this is useful, and comment if you have trouble when utilizing this! I’ll try to help the best as I can