by Ula Chwesiuk Jul 17, 2024

Changing an email service provider can be challenging, but we’d like to show you it doesn’t have to be. The transition can be smooth and hassle-free. On the example of migrating from SendGrid to Elastic Email, we will walk you through all the important steps to get started, integrate with our email API, and start sending. You will learn about our API libraries, documentation, and differences in references.

API Libraries

The easiest way to integrate with our email API is to use one of our API libraries and frameworks. We’ve prepared and constantly maintain downloadable libraries for 12 programming languages. Each of them includes authentication and installation instructions, a quick start guide, code samples, and other useful resources. Here are our libraries:

If you cannot find the library you’re looking for, let us know at contact@elasticemail.com

How to get started

Let us move on to the essential steps - how 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. That is why we prepared some of the most crucial API references for both Twilio SendGrid and Elastic Email:

API Name

Email Marketing platform | Elastic Email Email Marketing platform | Elastic Email
Introduction
Introduction Email API Onboarding
Authentication
Authentication Authentication
Sending Emails
Emails Sending email
Managing Suppressions
Suppressions Suppressions
Managing Templates
Templates Transactional Templates
Inbound Email Processing
Inbound Route Inbound Parse
Statistics
Statistics Stats

Signing up

To start your migration process, you need to sign up for an Elastic Email account first and choose the Email API product. Creating an account on our platform is completely free of charge, and you do not need to provide any credit card details during the registration. Once you sign up, you will receive a confirmation email to verify your account.

Setting up a sending domain

After creating your Elastic Email account, you need to add and verify your sending domain. To do it, you will need to log into your domain provider and adjust the DNS settings of your domain. For more information, check out our help article on how to verify your domain or watch our YouTube guide below:

Creating your API key

To start using our email API, you will need to authenticate yourself with an API key. To generate it, 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.

After creating your API key, please keep it safe, as you will need your API key for every call you make in order to identify yourself and confirm your account’s credentials. 

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 make your migration process easier and quicker, we recommend downloading and installing a repository of the programming language you use. Both SendGrid and Elastic Email have a large collection of email API libraries and SDKs of many programming languages. Just like you integrated with SendGrid’s email API by installing a library or SDK, you need to do the same with Elastic Email. 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.

Npm

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 Twilio SendGrid API looks like:

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'test@example.com',
  from: 'test@example.com', // Use the email address or domain you verified above
  subject: 'Sending with Twilio SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
//ES6
sgMail
  .send(msg)
  .then(() => {}, error => {
    console.error(error);

    if (error.response) {
      console.error(error.response.body)
    }
  });
//ES8
(async () => {
  try {
    await sgMail.send(msg);
  } catch (error) {
    console.error(error);

    if (error.response) {
      console.error(error.response.body)
    }
  }
})();

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.

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: "johnsmith@domain.com",
            Fields: {
                name: "John"
            }
        }
    ],
    Content: {
        Body: [
            {
                ContentType: "HTML",
                Charset: "utf-8",
                Content: "<strong>Hi {name}!<strong>"
            },
            {
                ContentType: "PlainText",
                Charset: "utf-8",
                Content: "Hi {name}!"
            }
        ],
        From: "myemail@domain.com",
        Subject: "Example email"
    }
};

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

Email API migration guide: conclusion

Now you know all the essential steps for migrating from Twilio SendGrid to Elastic Email. If you have any questions about how to integrate with our email API, do not hesitate to contact our customer support team. They are available to you 24/7 via email at support@elasticemail.com 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:
author default image

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.

Icon green check Instant setup Icon green check No credit card required