# Using Email APIs to send and receive emails

MailSlurp is a free email API for creating email accounts on demand that can send and receive real emails from code or tests.

# What is an email API?

Many applications and businesses today depend on email. Email powers user sign-up, invoicing, payments, communication and more. Email has been around for a long time but the underlying SMTP technology hasn't changed much. That's why Email APIs are becoming increasingly popular with developers, QA testers, and content managers. Email APIs add modern features to email allowing us to go beyond email's original constraints.

# What's wrong with SMTP

SMTP (Simple Mail Transfer Protocol) is simple: it's solid and reliable but not very flexible for modern use cases. Setting up multiple email addresses is time-consuming and confusing. Have you ever configured your domain provider with TXT and MX name records? What about spam rating and DKIM? Never heard of any of these terms? Don't worry, email APIs provide all the features of standard mail servers plus more.

# What can email APIs do?

Email services like MailSlurp abstract SMTP into more approachable and extensible concepts.

API means "application programming interface": like a set of buttons on a machine that abstract complex tasks into a single click.

APIs like MailSlurp let users create email addresses instantly. APIs let developers send and receive emails from many different environments, like mobile applications, webservers, embedded devices and more.

# What does an email API look like?

APIs usually resemble a collection of commands that a server or website can interpret. By sending commands to the server it will take action on behalf of the sender. For example here is how you would create an email address for testing in Javascript using MailSlurp:

const { emailAddress } = await mailslurp.createInbox();

# What is the difference between SMTP and an email API

The main difference between SMTP and an email API is ease of use and what you can do with it. SMTP is traditionally complex to configure and most people use some tool like Gmail or Outlook to manage their accounts. These tools are great for casual use but for complex operations SMTP shows brittleness. Email APIs like MailSlurp are fast to establish and can scale with your needs - much faster than SMTP servers.

# What are some use cases?

Thousands of developers use MailSlurp to generate test email accounts, receive emails in code, parse attachments and validate email content. The also use it to send templated HTML emails and attachments en-masse. Doing so in SMTP requires a lot of head scratching.

# What are some examples?

Users of MailSlurp have used the email APIs to test user sign-up end-to-end. This means testing an application's account creation process in an automated way using real email addresses. Customers have found this to be a life-saving feature for production software: imagine knowing instantly if code changes have affected your user sign-up process.

// email apis can be used to extract email content
// like sign-up confirmation codes
const { body, subject } = await mailslurp.waitForLatestEmail(inbox.id);
const confirmationCode = /[0-9]{6}$/.exec(body)[1];

# Any more?

Other email API examples include testing transactional email content or automated messaging. Many applications today send emails in response to a user's actions. These emails should be tested automatically whenever code changes in order to confirm their validity. With MailSlurp you can create email addresses dynamically, send emails to them from your application, and then validate them from within tests or view their content in a visual dashboard.

# How do I get started?

Get started for free today at app.mailslurp.com.