Blog

What is an email API and how it can help optimize your transactional email

Amy Elliott Amy Elliott
· 15 min read · Tips and resources · July 28th, 2023
An email API helps grow your business by enabling you to create exceptional brand experiences that drive customer engagement and build relationships.

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.

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 session to help you start using MailerSend’s API for your apps and websites.

Looking for an email API?

Learn more about MailerSend's flexible and reliable email API solution.

What is an email API?

An API (Application Programming Interface) enables two or more applications or programs to interact with one another. For example, a weather API allows developers to implement automatic querying of weather data in order to deliver information to a weather application. This allows for weather forecasts and updates to be delivered in real-time.

An email API enables other applications to use the functions of an Email Service Provider’s (ESP) platform. People use email 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 an email triggered by recent activity on your app, like the example below. 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.

The alternative to using an ESP’s features via email API is to access them through the ESP’s Graphical User Interface (GUI). For example, you can head to the MailerSend Activity page and search for delivered emails by entering the time period, selecting the Delivered tag, and then clicking the search button.

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"]
}

Check out our email API glossary below to sharpen your knowledge of related terms.

How does an email API work?

An email API, like other APIs, is an intermediary that sits between an application and a server. It allows you to use HTTP POST requests to send outbound emails from your app or website. 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.

Here’s a post office metaphor to help illustrate the point. 📮

  • Parcel collection (the endpoint) is one of the many services (endpoints) offered 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!

What is an email API endpoint?

API endpoints are URLs or URIs that point to a location or address on a web server where a particular service or resource can be accessed. They are used as entry points, allowing developers to make requests to interact with a specific functionality provided by another application or service. 

In the context of email, email API endpoints are provided by email service providers—like MailerSend—to allow developers to programmatically interact with the email system. They allow for the sending, receiving and managing of emails using standard HTTP methods (GET, POST, DELETE, etc.).

Here are some examples of MailerSend’s email API endpoints:

POST https://api.mailersend.com/v1/email

This endpoint is used to send an email. The client application would make a POST request with the necessary parameters, such as the recipient's email address, the subject, the email content, etc.

POST https://api.mailersend.com/v1/bulk-email

This endpoint is used to schedule bulk email. The client application would make a POST request with the necessary parameters, such as the recipient's email address, the subject, the email content, etc.

GET https://api.mailersend.com/v1/activity/{domain_id}

This endpoint is used to retrieve a list of activities. The client application would make a GET request with the necessary parameters such as the dates from and to, and event. 

DELETE https://api.mailersend.com/v1/identities/{identity_id}

This endpoint is used to delete a sender identity. The client application would make a DELETE request with the identity id URL parameter. 

PUT https://api.mailersend.com/v1/inbound/{inbound_id}

This endpoint is used to update an inbound route. The client application would make a PUT request with the necessary parameters, such as the inbound domain, inbound priority, and match filter, etc. 

Check out all of MailerSend's API endpoints in our API reference.

Using email API to streamline transactional email

1. 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 confirmation emails, password resets, account activations, abandoned carts, and welcome emails.

Take advantage of this high engagement by sharing your personality, building relationships and driving conversions. Use your emails to put your brand in front of recipients, share attachments, and utilize templates using an email endpoint.

Transactional email API use case examples

Email API is great for sending all kinds of transactional messages and notifications, including:

E-commerce emails

SaaS emails

Banking & finance emails

  • Order confirmations

  • Shipping notifications

  • Delivery notifications

  • Invoices

  • Payment failures

  • Product review requests

  • Customer service

  • 2-factor authentication emails

  • Password reset requests

  • Account creation notifications

  • Account activity summaries

  • Security alerts

  • Terms of service updates

  • Billing notifications

  • Subscription renewal and expiry notifications

  • Customer service

  • Security alerts

  • Payment notifications

  • Account activity alerts

  • Security alerts

  • Account balance updates

  • Upcoming payment alerts

  • Loan approvals

  • Customer service

  • E-statements

Health & beauty services

Travel services

Food and drink

  • Appointment confirmation emails

  • Appointment reminders

  • Cancellation confirmations

  • Reschedule requests

  • Review requests

  • Customer service

  • Ticket confirmation emails

  • Travel itineraries

  • Accommodation booking confirmations

  • Booking reminders and important information

  • Review requests

  • Customer service

  • Reservation confirmations

  • Reservation reminders

  • Cancellation confirmations

  • Reservation change confirmations

  • Review requests


2. 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.

3. 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.

4. 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, by 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. 

For example, you could schedule all feedback request emails to be sent out once a day at the same time, rather than being triggered at separate times for each individual recipient. Use the bulk email endpoint to optimize your sending in this way.

5. Manage templates

Sending emails via API allows you to create and use templates to give your messages a professional look. You can use the API to quickly fetch a list of templates or view an individual template’s data, such as bounces, sent, and delivered, without needing to scour through tons of templates to find the information you need. You can also quickly delete any template by sending a DELETE request to the template’s endpoint.

6. Enhance emails with personalization

You can easily personalize your emails by inserting variables into your template to be populated in the API call. Make use of personalization for basic information such as name or account number or use more advanced personalization for conditional statements, for loops, and filters to add dynamic tables, fallback values and conditional dynamic messaging.

API vs SMTP

Choosing between email API and SMTP (Simple Mail Transfer Protocol) for your email delivery depends on how much functionality and additional features you need for your use case. Here’s a breakdown of the advantages and disadvantages of both:


Email API

SMTP

Advantages

No need for in-depth knowledge of email protocol or servers


Feature-rich: Get access to advanced email tracking, templates, analytics, and more


Highly scalable, designed to handle large volumes of email with ease


Straightforward implementation with SDKs and documentation


Generally more secure

More personalization options & the ability to use delays and triggers


Easier to send emails and automate processes via your app

No coding needed if using an SMTP relay service


Quick and easy way to start sending emails


Universally supported


Easy to migrate between services

Compatible with most legacy systems

Disadvantages

Some technical knowledge and coding skills are required

Migrating between services is more complex



If not using a third-party SMTP service, knowledge of email protocols and servers is needed


More potential points of failure due to multiple back-and-forth communication between servers


Some firewalls block some commonly used SMTP ports


Lack of additional features for more advanced tracking, analytics and templates


Generally not as secure, needs additional security implementation

Cannot use Advanced personalization

If you’re looking to integrate advanced email sending into your app, with automated workflows, custom templates and advanced personalization, email API is the way to go. A third-party SMTP service can be highly effective, and is a great no-code solution for those looking to quickly start sending emails. However, email API will always offer more flexibility and customization options.

Benefits of using an email API

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.

As mentioned above, it’s easy to manage compared to running your own email server and offers more advanced features and functionality than an SMTP relay service.

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

1. 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.

2. Build one-to-one relationships

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

3. 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 by an infrastructure optimized for deliverability.

4. Enable two-way communication

People love interacting, and with an email API, you can use an inbound routing endpoint to enable them to respond to comments, send messages and interact with your app via email. In MailerSend, we’ll receive the email on your behalf, parse the contents and then route it to your app or another email address.

5. Get started quickly

Email API integration is simple to set up and most third-party email API services, like MailerSend, will provide the SDKs and documentation you need to get started. Although knowledge of coding is necessary, developers can integrate email with an API in minutes.

6. Use with ease

Once you’re all set up, email sending is automated, making it an extremely efficient way to deliver transactional emails to your customers. What’s more, in MailerSend, non-technical users can easily edit templates and manage transactional emails through the GUI while developers can use the API to take care of the rest.

Start sending with email API

Sign up to MailerSend and get 3,000 emails/month free, forever.

What to look for when choosing an email API provider

There are tons of email service providers on the market, all offering different features and plans. Of course, choosing the right service for your business will depend on the volume of emails you’ll be sending, as well as the features you need. But there are a few features that the best email API services will include.

Customer support: Do they offer 24/7 support and multiple channels such as email and live chat? What do reviews say?

Clear comprehensive documentation: Extensive guides, resources and API reference

Reliability and Performance: What do they say about performance and deliverability? What are the customer reviews like?

Scalability: Can the service scale easily with your business? Do they offer plans that will work as your business grows?

Security: Does the service have standard security features in place?

Features: Do they offer features such as advanced reporting, email verification, inbound routing and SMS? Plus the other features you need for your business. 

Integration Ease: Can the solution be implemented easily and do they offer onboarding support?

Cost Effectiveness: Does the price feel right for the volume of emails and features offered?

Reputation: Check out reviews on platforms like G2 Crowd and Capterra, are they mostly favorable?

Flexibility and Customization: Is it easy to customize the solution to fit your business?

Compliance: Do they comply with data privacy regulations such as the GDPR?

MailerSend ticks all these boxes. Check out our features and pricing.

How API costs are calculated

Generally, APIs are priced based on a few different metrics, including per API key, per API call, and per the number of elements in an API request or response. For example, if each API call is charged at $0.05, then 10 API calls will cost the users $0.50.

Email service providers use these metrics to devise fair pricing models for users, where the larger the volume of emails, the lower the cost. MailerSend, for example, offers a free plan that includes 3,000 emails per month and 1,000 daily API requests. For larger volumes and more features, the Starter plan starts at $28 per month for 50,000 emails and 100,000 daily API requests.

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 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 to make 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 PHP, cURL, Java, Ruby, 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."
}'
Note:

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.

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 creating your first calls to MailerSend’s endpoints!

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

Try MailerSend’s email API for free

Sign up and get 3,000 emails/month free plus access to advanced features like tracking and email analytics, email builders, suppression management and more.

Amy Elliott
I’m Amy, Content Writer at MailerSend. 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.