Integrating Amazon Simple Email Service(SES) with Salesforce Lightning Web Component (LWC)
In Salesforce, we often use the functionality to send emails either from the UI or from the apex. But as we know Salesforce comes with governing limits, and there is a limit on sending daily emails i.e. 5,000.
So what if you have a requirement to send emails for more than 5,000, therefore we need a solution from an external resource or a third party.
So in our case, we are going to explore how we can send emails using Amazon Simple Email Service through LWC.
- Setting up AWS -
I am assuming that you have created or have an account on AWS.
By default, AWS SES prevents spamming and can only send and receive emails from verified addresses.
Go to Simple Email Service > Email Addresses.
Click on Verify a New Address button add your email and go to your inbox and verify your email address. After verification, you will see your email address in Email Address Identities.
You can also verify a domain.
2. Uploading AWS SDK to Salesforce -
Download AWS SDK from here aws-sdk and upload it as a static resource — awsjssdk.
3. Add https://email.<region>.amazonaws.com in the remote site setting.
4. Create and download your AWS access keys -
- Navigate to My Security Credentials
- Navigate to the user Add User.
- Follow the steps give him Programmatic access -
- Assign Appropriate permission sets AmazonSESFullAccess then Next and Create User.
- Download the CSV with the access key and secret access key.
5. Create an LWC and import the static resource -
ToAddresses: Array of verified email addresses for whom you want to send an email.
Body.Html.Data: HTML message template. All the styles have to be in line.
Body.Subject.Data: Subject of the email.
Source: Email address of the sender.
ConfigurationSetName: This is required if you want to receive notifications using SNS.
- In Salesforce, you can not use node js for AWS-SDK therefore we need a raw SDK that will provide us with pre-built methods to send emails and overcome the problem of the daily limit of Salesforce.
- You can explore more about AWS.SES from here.
- To know more about using Email templates you can click here — Using AWS SES Email Template