strings.no_script

What Are Email APIs and How to Use Them - MailerSend

How an email API helps you create a solid brand experience

MailerSend’s API does much more than send transactional emails. It can help you grow your business by driving customer engagement, building one-to-one relationships, and delivering a good brand experience. Learn how!

An email API doesn’t get the recognition it deserves. When we receive a welcome email immediately after signing up for a new account, for example, we don’t think too much about how it’s done. We just expect that an email will be waiting in our inbox.

In fact, email APIs play an important role in driving the interactive experience that we have come to expect when we transact online. From the start to the end of a customer journey, the email API is working tirelessly to automate email sending.

It’s easy to be intimidated by APIs as much of their work is unseen. The good news is that you can work with APIs by entering a URL in your web browser. You don’t need to be a developer to harness the benefits of an API for your business!

Come behind the scenes with us as we lift the curtain on email APIs. You’ll learn about what they are, how they work, and finish with a hands-on practical session that will get you started on using MailerSend’s API for your apps and websites.

What is an email API?

An email API is an application programming interface (API) that enables other applications to use the functionality of an email service provider (ESP). People use APIs to quickly integrate email services into their apps and websites using code.

You may want, for example, to send email notifications about recent activity with your app. Grab, a major ride-hailing company in Southeast Asia, automatically follows up with your ride by sending you a nice thank you email when you leave a tip.

Grab email to thank you for a tip


The flipside to using an email API is to use the ESP through a Graphical User Interface (GUI). If you wanted to search for delivered emails in MailerSend, for example, you would enter the time period, select the Delivered tag, and then click the search button.

MailerSend Activity tab


The same task can be done with the activity endpoint of MailerSend’s API. You can perform this task repetitively without the involvement of humans and you can share the results with your technology stack. Here’s the code to retrieve delivered emails:

GET https://api.mailersend.com/v1/activity/jpr9086zdxgw63dn 

Body: 
{
    "limit":"2",
    "date_from":"1615824000",
    "Date_to":"1616342400",
    "event" : ["delivered"]
}

Why you should use MailerSend’s API

You have a couple of options to send emails from your apps. You could build your own email server but you will need resources and teams to maintain it. Or use an SMTP relay service but its simplicity lacks advanced features like dynamic content for emails.

An API like MailerSend’s gives you ease of use and effective integration of email sending in any app. Plus, team-based tools enable developers to interact with the app using API calls while designers work on email templates using various email editors.

But the real reason why an email API rocks is that it will help you deliver a better customer experience and grow your business!

Drive customer engagement

You can keep customers engaged and motivate them to interact with your brand by sending timely updates and progress notifications. MailerSend’s activity endpoint together with webhooks enables you to send triggered messages at the right time.

Build one-to-one relationships

A single mass email is unlikely to resonate with your customers! Talk to individual customers instead with highly personalized emails. Generate dynamic content on the fly for each recipient by using MailerSend’s email endpoint and templating engine.

Deliver a good experience

Your customers are on a journey that starts with your marketing emails and continues with your transactional emails. Give them a smooth and consistent brand experience by designing professional templates that get sent on infrastructure optimized for deliverability.

How does an email API work?

An email API, like other APIs, is an intermediary that sits between an application and a server. Human users interact with the application via a GUI. Other applications can also talk directly to the API by making API calls using programming languages.

API workflow

Technically speaking, an application sends a request to the API using the available endpoints listed in the API documentation. Authentication is done using an API token before the server accepts the request, sending a response using HTTP status code.

Let’s illustrate this with a post office example, shall we? 📮

  • Parcel collection (the endpoint) is one of the many services offered (the API documentation) in your local post office

  • You’re not allowed in the mailroom (the server) so you ask the kind postmaster (the API) to retrieve your parcel (the request)

  • The postmaster checks your ID (the API token) before disappearing into the mailroom and returning with your parcel (the response)

And there you have it, a simplified explanation of how an email API works using post-office-speak!

Use cases for MailerSend’s API

Send transactional emails

The programmatic nature of MailerSend’s API is perfect for automating email workflows around transactions. These emails enjoy higher open rates than those sent by email marketing campaigns because recipients expect to receive them.

Check out 14 examples of transactional emails for e-commerce order confirmations, password resets, account activations, abandoned carts, and welcome emails.

Take advantage of this high engagement by sharing your personality, building relationships and driving conversions. Put your brand in front of recipients by sending emails, sharing attachments, and utilizing templates using MailerSend’s email endpoint.

Fetch email information

MailerSend’s API can retrieve email information, pushing the data to your app or integrating it with the apps in your stack. With the domains endpoint, you can fetch a list of your domains, the recipients for each domain, and the emails sent to each recipient.

Or you could get insights into customer engagement by building a real-time digital dashboard, for example. Use the analytics endpoint to parse email metrics like the country, user-agents and reading environment, then optimize your emails for your recipients.

Manage your account

Enjoy total control over your account settings without having to use the MailerSend app. Easily manage webhooks, tokens and domains by making API calls to add, update and delete them—including those of an app’s customers! Or pause your domain and update its tracking options with the settings endpoint.

Getting started with MailerSend’s API

It’s time to move beyond the theory of APIs, and talk about the fun, practical ways you can use MailerSend’s API. Before we can begin, you first need to have a MailerSend account, a verified sending domain, and a terminal app like Postman or Insomnia.

Note: MailerSend is a RESTful API, meaning that it communicates using web standards like making requests using HTTP methods, responding with HTTP status codes, and formatting data in JSON. Read more at the API documentation.

All good? Let’s start!

1. Navigate to the Domains page of your MailerSend dashboard.

2. Click on Manage next to the domain that you wish to send an email from.

3. Click on Generate new token to create an API token so that you can link your app and MailerSend.

4. Scroll down to the Sending instructions section of the page. You’ll find a few code examples to send your emails using cURL, PHP, Laravel, Node.js, Go and Python.

Official MailerSend client libraries are available for PHP, Laravel, Node.js, Go and Python.

5. Copy and paste the cURL command into your terminal. You’re going to send an email by making an HTTP POST request to the API at https://api.mailersend.com/v1/email.

curl -X POST \
https://api.mailersend.com/v1/email \
-H 'Content-Type: application/json' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Authorization: Bearer {place your token here without brackets}' \
-d '{
"from": {
"email": "your@email.com"
},
"to": [
{
"email": "your@email.com"
}
],
"subject": "Hello from MailerSend!",
"text": "Greetings from the team, you got this message through MailerSend.",
"html": "Greetings from the team, you got this message through MailerSend."
}'
Remember to replace the API token and to values with your own. The from email address should be the same verified domain that you create an API token for.

6. Check the status of your email message in the Activity tab of your MailerSend dashboard.

Congratulations, you just sent your first email using MailerSend’s API! 🎉

The next step is to learn how to send email attachments, personalize your emails and use email templates with our handy guide, How to start sending emails.

Essential API glossary

API

An intermediary that allows two apps to talk to each other by defining standard rules used for communication.

API token

Sometimes referred to as an API key, is a unique string of numbers and characters that authenticates an application before it is allowed access to an API. It is enclosed in the authorization header that accompanies every request.

Client

The user side of a web application sitting on the opposite end of a web server. It typically describes the web browser.

Email API

A software intermediary that provides the functionality of an email service provider to other applications via code.

Endpoint

The touchpoint of an API where two applications communicate with each other. APIs have many endpoints, for example, to send emails, fetch email activity, and so on.

GUI

A Graphical User Interface is a visual way of interacting with an application using windows, icons, menus and a pointer.

HTTP method

Request actions that you can perform with a REST API, including GET to retrieve data and PUT to replace data.

JSON

Stands for JavaScript Object Notation, a lightweight data format used to exchange data between a web server and a client.

REST

REpresentational State Transfer is a software architectural style that uses web standards like HTTP to create interactive web applications.

SMTP relay

An email delivery service that routes messages through email servers based on the industry-standard Simple Mail Transfer Protocol.

Web API

An API based on REST software architecture that uses web standards to enable two applications to communicate with each other.

Webhook

An HTTP callback that makes HTTP requests to a URL endpoint. It is used for real-time messaging triggered by events in a web app.

Web server

The other half of a client/server model consisting of hardware and/or software that accept and fulfill HTTP requests over the Internet.

You’ve taken the first few steps

Now that you’ve been introduced to APIs and sent your first message with MailerSend, continue this momentum by studying our API documentation and create your first calls to MailerSend’s endpoints!

How would your use cases benefit from MailerSend’s API endpoints? Share in the comments below.

Sean
I’m Sean, Content Writer at The Remote Company. I enjoy going on long leisurely walks in big cities, seeking the weird and wonderful in hidden places.