Blog

How an email API helps optimize your transactional email

Amy Amy
· 13 min read · Tips and resources · May 17th, 2022
An email API can help you grow your business by driving customer engagement, building relationships and delivering an exceptional brand experience.

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 and 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 functions of an email service provider’s (ESP) platform. People use APIs to quickly integrate email services into their apps and websites using code. This includes sending transactional messages, scheduling bulk email, fetching email and recipient information, and managing accounts. 

For example, you may want 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"]
}

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.

Example of 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!

Why you should use an email 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. Alternatively, you could use an SMTP relay service, but its simplicity lacks advanced features like dynamic content for emails.

An API enables you to harness the advanced features and functionality of your email platform quickly and easily, allowing for effective integration of email sending in any app. Combine this with a user-friendly interface provided by your ESP, and developers can seamlessly interact with the app using API calls while marketing teams 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. For example, 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.

Start optimizing your transactional email today!

Sign up to MailerSend for free and take advantage of our advanced email API.

Using email API to streamline transactional email

Send transactional emails

The programmatic nature of 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 an email endpoint.

Fetch email information

An 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 your ESP’s 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.

Schedule bulk email

Bulk or batch emailing enables you to schedule multiple emails to be sent at a more optimal time. With bulk email, you can time messages for maximum impact, for example, syncing them with an event. 

You can also avoid peak sending times to boost email deliverability, as well as bypass rate limiting, as bulk emailing allows you to send thousands of emails in a single request. All you need to do to optimize your sending in this way is use a bulk email 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. You can also check out our blog post on how to send emails in your favorite programming language.

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

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.

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.

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.

You’ve taken the first few steps

An email API is an efficient way to gain maximum control over your transactional email sendings, templates, data and accounts. It gives an incredible level of additional functionality that developers can implement quickly and efficiently.

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.

Ready to transform the way you do transactional email?

Sign up now for free and get 12,000 emails per month.

Amy
I’m Amy, Content Writer at The Remote Company. As a child, I dreamt about writing a book and practiced by tearing pages from an A4 notepad and binding them with sugar paper. The book is pending but in the meantime, I love taking a deep dive into technical topics and sharing insights on email metrics and deliverability.
Stop War! Help Ukraine! See what you can do