What is an email API? And when to use one for your transactional email
- What is an email API?
- There are two types of email APIs: Transactional and marketing
- How does an email API work?
- Email APIs use endpoints to authenticate and route requests
- Common transactional email API use cases
- 1. Send transactional emails
- 2. Fetch email information
- 3. Manage your account
- 4. Schedule bulk email
- 5. Manage templates
- 6. Enhance emails with personalization
- 7. Debug and fix sending errors
- Email API vs. SMTP: Which one should you use?
- How to choose an email API provider
- Get started with MailerSend’s API
- You’ve taken the first few steps
- Transactional email API FAQs
When you add email to your app for the first time, the instinct for many is to wire up SMTP, grab a library, and move on. That works, but often you’d be better off with an email API instead.
Using an Email API is straightforward with the right tool and a good SDK. Plus, you get a ton of extra features like templates, email reporting, and inbound routing that help you build more advanced email sending into your apps.
In this guide, you will learn what email APIs are, how they work under the hood, when to use one over SMTP, and how to make your first API call.
Looking for an email API?
Learn more about MailerSend's flexible and reliable email API solution.
What is an email API?
An email API is a programmatic interface that allows developers to send, receive, and manage emails directly from their own application's code, rather than manually configuring email servers or using a traditional SMTP setup.
People use email APIs to quickly integrate email services into their apps and websites using code. This enables developers to do things like send transactional messages, schedule bulk email, fetch email and recipient information, and manage accounts.
There are two types of email APIs: Transactional and marketing
Transactional and marketing emails play different roles. Transactional emails are used for essential communication that is triggered by something the user did, while marketing emails are used to promote your product.
You need to understand the split to know which compliance rules apply, the types of content you can send, and which email API tools are best for your use case.
What is a transactional email API?
A transactional email API is built to let you send one-to-one emails triggered by a user action or system event. Common examples include password resets, order confirmations, shipping updates, receipts, OTP codes and account notifications.
Transactional emails:
Are mostly trigger-based: They are sent programmatically via API call when an event happens (user signs up, checkout completes, etc.)
Can be scheduled: Some types of emails are an essential part of the user experience, but they're not triggered in real-time by a specific action. For example, scheduled maintenance updates and account summaries
Are expected and time-sensitive: The recipient is anticipating the email as part of using your product, so delivery speed matters
Have no unsubscribe or consent requirements: While marketing emails require consent, transactional emails can be sent without it
Are almost always personalized: Transactional emails don't contain the same information for all recipients. They almost always contain information and data that is specific and relevant to the user, for example, order details or account usage stats
Need high deliverability and speed: Ever had to wait for a 2FA code? It’s not fun. Even a small delay in timing can cause an incredibly frustrating experience
Get exceptional engagement: Since these messages are expected and necessary, they get very high open rates
MailerSend's core use case is for sending transactional emails.
What is a marketing email API?
A marketing email API is built to let you send promotional emails to subscribers. This could be one-to-many campaigns or automated emails that go out based on subscriber activity:
Marketing emails:
Are often sent in bulk: Marketing emails are often sent in bulk to an entire segment or list
Require consent and unsubscribe mechanisms: You must have consent to send marketing emails. You must also include an unsubscribe link and address in the content
Can be automated: Like transactional emails, marketing emails can be automated. But, since the email content is promotional, you must collect consent before sending it
Deliver marketing results: Marketing email engagement isn’t as high as with transactional campaigns. But they are extremely effective for generating product sales
Because marketing and transactional emails have such different use cases, it’s best to use different services for each kind. For example, you can use MailerSend for your transactional emails and MailerLite for your marketing ones.
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.
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!
Email APIs use endpoints to authenticate and route requests
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.
Common transactional email API use cases
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:
|
|
|
Health & beauty services | Travel services | Food and drink |
|
|
|
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 create templates, 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.
7. Debug and fix sending errors
An email API gives you structured, queryable visibility into every send. For example, you can see:
Per-message status tracking: Each email gets a unique ID you can query to see its full lifecycle, from queued to sent, delivered, bounced, opened, clicked or complained
Webhooks and event streams: Real-time events get pushed to your own systems as they happen, so you can log failures, bounces, or spam complaints
Detailed error responses: API calls return specific error codes and messages (invalid recipient, auth failure, rate limit, malformed payload) at the moment of the request
Searchable send history: Logs are structured data (JSON) you can filter by recipient, template, date, or status
Correlation with your own app logs: Because you control the send request (with your own message IDs and metadata attached), you can trace an email back to the exact user action, order, or event that triggered it
Together, this means you can debug issues quickly, build an alerting system based on delivery data, and see the full lifecycle of each email.
Email API vs. SMTP: Which one should you use?
Email API and SMTP are two different ways to send email programmatically, and they're often compared because they’re both ways to get a message from your application to your recipient's inbox.
SMTP (Simple Mail Transfer Protocol) is the original protocol behind email delivery, dating back to the 1980s. To use it, you connect directly to a mail server, authenticate your domain, and send your message through a fixed sequence of protocol commands. It works reliably, but you're on your own for retries, message formatting, and troubleshooting. Plus, you get limited visibility into what happens after the message leaves your server.
An Email API sits on top of that same infrastructure, but replaces the raw protocol handshake with a simple HTTP request. You send a JSON payload with your content and recipient details, and the provider handles the SMTP transaction on the backend.
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 each:
Email API | SMTP | |
Advantages | No need for in-depth knowledge of email protocol or servers
More personalization options & the ability to use delays and triggers
| No coding needed if using an SMTP relay service
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
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.
Start sending with email API
Sign up to MailerSend and get 500 emails/month free.
What to look for when choosing an email API provider
To send emails via an API, you need an email API provider. There are tons of email service providers on the market, all offering different features and plans. The right service for your business will depend on the volume of emails you’ll be sending, the features you need, and whether you want to send transactional or marketing emails.
Here are some factors to look out for:
✅ 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.
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.
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."
}'
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 Emails 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 500 emails/month free plus access to advanced features like tracking and email analytics, email builders, suppression management and more.
Transactional email API FAQs
1. Can my app schedule emails with an API?
Yes, most email APIs, including MailerSend's, support scheduling by accepting a send_at parameter (a future timestamp) in the send request. The email is queued and dispatched at that time rather than immediately, which is useful for things like reminders, drip sequences, or time-zone-aware sends. It’s worth noting that even if you schedule an email for a particular time, the actual sending can be delayed by server load.
2. How are email API costs calculated?
Email 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 pricing starts at $7 per month for 5,000 emails and 1,000 daily API requests.
3. Can you test an email API for free?
MailerSend’s free plan lets you test the service by making up to 100 daily API requests and sending up to 500 emails a month. Once you know that you like the product, you can sign up to a paid plan from just $7 per month for 5,000 emails.
4. Do I need a different service for marketing and transactional emails?
MailerSend is built for transactional email sending. To send marketing emails, you should use an email marketing tool like MailerLite. This will give you dedicated features—such as automations, sales tracking and its own comprehensive email API—that help you create effective marketing campaigns.