Easily Integrate Transactional Email APIs with Salesforce

Sending Transactional Emails from Salesforce

Effective email strategies, particularly transactional emails, are vital in modern digital communication, ensuring customers receive timely and relevant information based on their interactions with a service or platform.

This blog post focuses on sending transactional emails from Salesforce and examines the limitations associated with Salesforce’s email capabilities. We will explore how leveraging Declarative Webhooks for API callouts to email vendors like SendGrid and Mailchimp can overcome these limitations.

We’ll delve into the various types of transactional emails and provide practical examples of both outbound and inbound callouts using Declarative Webhooks. This approach not only enhances your email strategy but also offers a robust alternative to Salesforce’s native email limits.

Types of Emails

Emails can be broadly categorized into the following types:

  1. Transactional Emails
  2. Marketing Emails
  3. Notification Emails

Transactional Emails are triggered by user actions and contain information about a transaction or process initiated by the user. Examples include order confirmations, shipping notifications, password reset emails, and account-related alerts.

Marketing Emails are promotional, aimed at encouraging the recipient to take some commercial action. These include newsletters, promotional offers, product announcements, and sales notifications.

Notification Emails are similar to transactional emails but generally relate to non-transactional activities, such as social media updates, reminders, and activity alerts.


What is a Transactional Email?

A transactional email is an automated email triggered by user actions on a website or application. These emails are not promotional but provide important information to the user, such as:

  • Order confirmations
  • Shipping notifications
  • Password resets
  • Account updates

Transactional emails have higher open rates compared to marketing emails because they contain information the recipient is expecting or needs urgently.


Declarative Webhooks for Email API Calls

Declarative Webhooks allows you to build integrations with most REST APIs with JSON calls inside Salesforce easily with few clicks.

It can execute integrations through Flow, buttons, scheduled batches, or Apex. Declarative Webhooks is free to use, so sign up for a trial here!

Key Features:

  • Ease of Use: No coding required to set up integrations.
  • Flexibility: Supports a variety of triggers and data formats.
  • Scalability: Suitable for both small and large-scale integrations.

Email APIs

Different email vendors provide APIs to facilitate the sending of transactional emails. Here, we will look at two popular email service providers: SendGrid and Mailchimp.

SendGrid API

SendGrid offers robust and scalable email APIs to send transactional emails. It provides features such as dynamic templating, tracking, and analytics.

Example: Sending an Order Confirmation Email with SendGrid

API Endpoint: https://api.sendgrid.com/v3/mail/send

Headers:

{  

“Authorization”: “Bearer YOUR_API_KEY”,
“Content-Type”: “application/json”

}

Body:

Mailchimp API

Mailchimp’s Transactional Email service (previously Mandrill) is known for its reliability and powerful analytics.

Example: Sending a Password Reset Email with Mailchimp

API Endpoint: https://mandrillapp.com/api/1.0/messages/send.json

Headers:

{

  “Content-Type”: “application/json”

}

Body:


Implementing Declarative Webhooks for Outbound Email API Callouts

Prerequisites
  • Salesforce Org: A Salesforce org with Declarative Webhooks installed.
  • API Endpoint: Access to the email service provider’s API endpoint for sending transactional emails.
Step-by-Step Guide
  1. Create a Callout Template
    Navigate to the Declarative Webhooks app in your Salesforce org and create a new outbound template.


Define the Entry Criteria

Define the entry criteria for your automation. This could be a new record creation, record update, or a specific field change and can be triggered from a Flow or an Apex trigger.

For this example, we’ll use an order creation Flow. Create a record triggered flow with the main object Order. 

Add an apex action for calling the outbound template record when this flow is executed (when an order is created.)

  1. Set Up the API Call
    Configure the API call to your email service provider. You’ll need to specify the endpoint, method (POST), headers, and body. The body will include dynamic data from the order record.
  1. Map the Fields
    Use the field mapping feature in Declarative Webhooks to map Salesforce fields to the corresponding fields in the API request.

    This ensures that the dynamic data (e.g., customer email, order number) is correctly passed to the email service provider.
  1. Test the Integration

    Test the configuration by creating a new order record in Salesforce. Check if the transactional email is sent successfully to the specified email address.

Transactional Email Tracking with Declarative Webhooks

For sending transactional emails signing up for the trial account, go to the settings section and create a new API key.

In this example, we will track the status of transactional email already sent by Mandrill.

We need to create an Inbound Template to process the data sent by Mandrill. The first step is defining a request body, which you can find an example of here.

After defining the request body, it’s time to use Inbound Call Actions to track the status of the email.

The final step is setting up the webhook itself. Go to the Mandrill app and on the webhooks tab define a new webhook.

In our example we want to update records if the transactional email is bounced, so we subscribe to the bounce event. Setting up webhooks while maintaining them can be tricky, while testing be sure to check the best practices in the last section.

Handling Multiple Email Types with Declarative Webhooks

Declarative Webhooks can manage different types of transactional emails by setting up multiple callout template configurations, each with its own entry mechanism and API call details.

  1. Order Confirmation Email:
    • Apex Trigger / Record Triggered Flow: Order creation
    • API Endpoint: /sendOrderConfirmation
    • Body: Contains order details
  2. Shipping Notification Email:
    • Apex Trigger / Record Triggered Flow: Order status update to “Shipped”
    • API Endpoint: /sendShippingNotification
    • Body: Contains tracking information
  3. Password Reset Email:
    • Apex Trigger / Record Triggered Flow: Password reset request
    • API Endpoint: /sendPasswordReset
    • Body: Contains reset link

Implementing Solutions to Circumvent Salesforce Email Limits

Salesforce has limits on the number of emails that can be sent per day. Using external email vendors like SendGrid and Mailchimp through Declarative Webhooks can help you bypass these limits while ensuring reliable email delivery.

Benefits of Using External Email Vendors
  1. Higher Daily Limits: Email service providers typically allow higher daily email sending limits compared to Salesforce.
  2. Scalability: Easily scale your email sending capabilities as your business grows.
  3. Reliability: Ensure email deliverability with robust infrastructure and reputation management.
  4. Tracking and Analytics: Gain insights into email performance with detailed analytics provided by the email vendors.
Steps to Implement the Solution
  1. Set Up Declarative Webhooks:
    • Install and configure Declarative Webhooks in your Salesforce org.
    • Define the necessary triggers/automation and API callouts to the email vendor.
  2. Configure API Integrations:
    • Set up API keys and endpoints for the chosen email vendor (e.g., SendGrid, Mailchimp).
  3. Test and Validate:
    • Thoroughly test the webhook configurations to ensure emails are sent correctly.
    • Validate the email sending limits and performance.
  4. Monitor and Optimize:
    • Monitor email delivery and performance using the analytics tools provided by the email vendor.
    • Optimize email content and send strategies based on the insights gained.

Best Practices

Data Security:

  • Ensure that API keys and sensitive data are securely stored and not hard-coded.
  • Use HTTPS endpoints to encrypt data in transit.

Error Handling:

  • Implement Declarative Webhook’s error handling to manage failed API calls and retries.

Scalability:

  • Optimize webhook configurations to handle high volumes of transactions.
  • Use batching and asynchronous processing for large datasets.

Compliance:

  • Ensure that transactional emails comply with relevant regulations (e.g., GDPR, CAN-SPAM).
  • Include necessary information such as unsubscribe links and company contact details where applicable.

Conclusion and Next Steps for Optimizing Salesforce Transactional Emails

Using Declarative Webhooks to set up transactional email API callouts to various email vendors like SendGrid and Mailchimp provides a robust and flexible solution for keeping customers informed.

By leveraging the no-code capabilities of Declarative Webhooks, businesses can quickly implement and scale their email notifications without extensive development efforts.

We have covered the types of emails, the specifics of transactional emails, and provided detailed steps to configure and test transactional email API callouts using Declarative Webhooks. Additionally, we have discussed how these solutions can help circumvent Salesforce email limits, ensuring reliable and scalable email delivery.

For further information and advanced configurations, refer to the Declarative Webhooks documentation and support resources. Thanks for reading!

If you want to learn more about Declarative Webhooks, please follow the links below: