An email API provides options to send the email via an HTTP interface that enables data transmission between your application to the email service provider such as Mailazy. typically you integrate code within your application and generate and send transactional emails, manipulate email templates, and access email metrics.
While many applications or frameworks use SMTP protocol for sending emails, developers can also leverage an email provider platform’s APIs to send emails.
Cloud email delivery is an example of SaaS, which stands for software as a service
. Cloud email delivery platforms provide services to send and manage your application transactional email messages, given the need for availability. Additionally, a cloud email delivery platform helps you manage your email reputation, and email authentication and also protects against security threats such as DDoS attacks, Internet outages, weather events, and other factors that can cause email sending problems.
Use-cases for email APIs
Email notifications and transactional emails are perfect use cases for an email API. Typical examples include:
- Authentication email such as account creation, password resets
- Alerts such as suspicious log-in notifications
- App error messages
- Purchase receipts
- Shipping notifications
Usually, the procedure of sending a transactional email with an email API could be like the following:
- An event occurs, such as an account login or a password reset, on a web-based service or mobile app.
- The authentication service communicates with cloud email delivery service API and provides such - information as the customer's email address, the details of the un-recognized login or password reset, and other details.
- The email service processes and creates a message with those details, using a template. (For example, different contents for password reset and for un-recognized login alert)
- Then the email service tries to deliver the message to the customer's or recipient's mailbox, handling the technical handshakes over the SMTP protocol and ensuring the email is delivered to the customer’s inbox.
- The email service provider record details about the delivery such as whether it failed and why, if it was opened, if the recipient clicked any of the links in the email, and so forth.
Advantages of Email API over SMTP
- Faster and flexible
- Easy integration
- Persistent HTTP connections to increase throughput
Getting started with Email API
Mailazy gives you easy access to interactive documentation and Email API library codes for your transactional emails. Statistical analysis of open, click, bounce, delivery, spam complaints, and unsubscribe reports on your Mailazy Dashboard.
Examples
curl
curl --location --request POST 'https://api.mailazy.com/v1/mail/send' \
--header 'X-Api-Key: <API KEY>' \
--header 'X-Api-Secret: <API SECRET>' \
--header 'Content-Type: application/json' \
--data-raw '{
"to": ["example@example.com"],
"from": "Sender <sender@example.com>",
"subject": "<Subject>",
"content": [
{
"type": "text/plain",
"value": "<Content>"
}
]
}'
Node.js
const MailazyClient = require('mailazy-node');
const client = new MailazyClient({ accessKey: '', accessSecret: '' });
const fn = async () => {
try {
const resp = await client.send({
to: 'test@example.com', // required
from: 'no-reply@example.com', // Use domain you verified, required
subject: '', // required
text: '',
html: '',
reply_to: 'someone@example.com'
});
console.log('resp: ' + resp);
} catch (e) {
console.log('error: ' + e);
}
};
fn();