by Ula Chwesiuk Jun 4, 2024

Changing your email API provider can be swift and hassle-free. Using the example of switching from Mailgun to Elastic Email, we've put together an email API migration guide for you. You will find all the information you need to start using our platform - differences in terminology, our resources, libraries, documentation, and how to integrate with our email API step-by-step.

API libraries

We have prepared and constantly maintain API libraries for various programming languages and frameworks. Our downloadable libraries are often accompanied by guides for authentication, code samples, and other useful resources. We currently have libraries for 12 languages:

If you cannot find the library you’re looking for, let us know at

How to get started

Let us walk you through all the steps you need to take to set up your Elastic Email account, integrate with our email API, and start sending emails.
We also prepared comprehensive API documentation so that you can integrate with our email API and use it according to your sending needs. Looking at API documentation is the best way to see the difference between email service providers. To simplify matters, we prepared a comparison of the most essential API references for both Elastic Email and Mailgun:

API Name

Email Marketing platform | Elastic Email Email Marketing platform | Elastic Email
Introduction Introduction
Authentication Authentication
Sending Emails
Emails Messages
Managing Suppressions
Suppressions Bounces
Managing Templates
Templates Template Storage
Email Lists
Lists Mailing Lists
Inbound Email Processing
Inbound Route Routes
Events Events
Statistics Stats

Signing up

To get started, sign up for an Elastic Email account. Choose the Email API product and create your account for free. No credit card details are required. You will then receive a confirmation email to verify your profile.

Setting up a sending domain

Once you created your Elastic Email account, it’s time to add your sending domain and verify it by adding the DNS settings. Check out our help article to learn how to verify your domain step-by-step, or watch our guide video below:

Creating your API Key

To provide valid authentication and start using our API, you will need an API key. To generate your API key, enter settings on your Elastic Email account and go to Settings -> Manage API Keys -> Create.

At this point, you can set custom permissions and optional access for your API key.

Once you create your API key, keep it safe as it will be used for every API call you make in order to identify you and confirm your account’s credentials. You can create up to 15 API keys. 

Your API key should be sent inside the header with the parameter name ‘x-elasticemail-apikey’ and your API key as a value.

Installing API library

To start sending emails via our email API, we highly recommend downloading a repository of the programming language you use and installing it. Both Mailgun and Elastic Email have a rich selection of email API libraries and SDKs of many programming languages. It will make the migration process very easy and convenient for you. Just as with Mailgun's email API integration you installed a library or SDK, you need to do the same with Elastic Email. Remember that all our downloadable repositories are available on Github.

Let’s show you the installation process using JavaScript. For example, when you want to install the repository for Node.js.


To publish the library via npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm install @elasticemail/elasticemail-client --save

Sending your first email

Let us first take a look at what sending an email via Mailgun API looks like:

const formData = require('form-data');
  const Mailgun = require('mailgun.js');
  const mailgun = new Mailgun(formData);
  const mg = mailgun.client({username: 'api', key: process.env.MAILGUN_API_KEY || 'key-yourkeyhere'});
mg.messages.create('', {
    from: "Excited User <>",
    to: [""],
    subject: "Hello",
    text: "Testing some Mailgun awesomness!",
    html: "<h1>Testing some Mailgun awesomness!</h1>"
  .then(msg => console.log(msg)) // logs response data
  .catch(err => console.error(err)); // logs any error

If you want to send your first email via Elastic Email, you need to load the library, get client instance, use your newly generated Elastic Email API key, and create an instance of EmailsApi that will be used to send the email. The 'key-yourkeyhere' for the API key in Mailgun is now replaced by "YOUR_API_KEY"

Based on the JavaScript example, here’s the whole code for sending an email to copy and paste:

const ElasticEmail = require('@elasticemail/elasticemail-client');

const client = ElasticEmail.ApiClient.instance;

const apikey = client.authentications['apikey'];
apikey.apiKey = "YOUR_API_KEY";

const emailsApi = new ElasticEmail.EmailsApi();
const emailData = {
    Recipients: [
            Email: "",
            Fields: {
                name: "John"
    Content: {
        Body: [
                ContentType: "HTML",
                Charset: "utf-8",
                Content: "<strong>Hi {name}!<strong>"
                ContentType: "PlainText",
                Charset: "utf-8",
                Content: "Hi {name}!"
        From: "",
        Subject: "Example email"

const callback = (error, data, response) => {
    if (error) {
    } else {
        console.log('API called successfully.');
        console.log('Email sent.');
emailsApi.emailsPost(emailData, callback);

Email API Migration guide: wrapping up

We hope you are now equipped with all the essential information and resources you need to migrate to our email API. If you have any questions or need additional assistance, our customer support expert will be happy to help you from day one. They are available to you 24/7 via email at or via live chat, which you can find in the bottom right corner of our website and platform. 
Haven’t you signed up for an Elastic Email account? Try it out and start sending emails with us today!

If you like this article, share it with friends:

Ula Chwesiuk

Ula is a content creator at Elastic Email. She is passionate about marketing, creative writing and language learning. Outside of work, Ula likes to travel, try new recipes and go to concerts.

Related Articles

Ready to get started?

Tens of thousands of companies around the world already send their emails with Elastic Email. Join them and discover your own email superpowers.

Instant setup No credit card required