Sending Mailgun Emails from Smartflows via AWS


To send email from SmartFlows using Mailgun, you need the following:

  • AWS Identity and Access Management (IAM) permissions for Lambda to execute the API call.
  • npm and Node.JS installed on your local machine
  • A Mailgun Account.
  • A Lambda function with logic for sending email via Mailgun API

Note: The example Lambda function code in Node.js is provided as-is. Adapt the example to your use case, or design your own in your preferred programming language.

Configure Mailgun

Follow Mailgun’s Quick Start Guide. Your API Key and Domain will be needed in future steps.

Install Mailgun Dependencies Locally

  1. Download the Mailgun dependency files.
  2. Create a new Node.js package.
  3. Install the Mailgun package to your new package.
  4. Add the following code to the index.js file:
var aws = require('aws-sdk');
const https = require('https'),
config = require('./config.json'),
mailgun = require('mailgun-js')({apiKey: config.MAILGUN_API_TOKEN,        domain: config.MAILGUN_DOMAIN})
exports.handler = (event, context, callback) => {
data = {
from: event.from,
subject: event.subject,
text: event.text
mailgun.messages().send(data, (error, body) => {
  1. Create a .zip file with your package.

Create an AWS Lambda Function

  1. Open the AWS Lambda Console.
  2. Choose Create a function.
  3. For Function name, enter "my-email-function".
  4. Choose Create function.
  5. Select Upload a .zip file from Code Entry Type.
  6. Upload your Mailgun Package.

Add an API Trigger

  1. Select Add Trigger.

  1. Select API Gateway from the dropdown.
  2. Select Create a New API from the API Dropdown.
  3. Select the REST API template.
  4. Click Add.

Update Your SmartFlow

  1. Add an External Web Call action to your flow.
  2. Configure the action as follows:


URL OF SERVICE: Url created in API Gateway

CONTENT-TYPE: application/json


"toEmailAddress": "Enter the email address of the recipient",
"fromEmailAddress": " A verified Amazon SES identity (domain or email address).",
"subject": "My test email subject",
"text": "Hello from SmartFlows"
  1. Save and Deploy your flow.

You can now activate your flow and an email should be generated.