MailJet is a SaaS API for sending transactional emails. These emails are usually triggered by your application in response to a particular event. An example is sending an email to a new user when they sign-up.

How does it work?

MailJet facilitates the sending of email templates in real time. This is an important requirement for email campaigns or a busy support team. It provides drag and drop email editors and email builders support multiple languages (such as English French German and more). You can also use the mailjet api to send emails from your own application.

What does it solve?

Services like MailJet make sending emails easy by abstracting SMTP protocols behind HTTP APIs, SDKs, and client libraries. This means you can concentrate on the emails you send not on how you send them. You can also manage contact properties from within the MailJet dashboard, perfect for customer support.

Sending an email with MailJet

MailJet has great API documentation and many official libraries. You can use MailJet with any language but for this article let's see how to send an email using the Node/Javascript library.

First add MailJet as a dependency in the node project. .

Then to send an email create an MailJet instance and invoke a send request on it.

Email contents

The simplest transactional email you can send will simply have one recipient, a subject line, and some text. Most users want more however and will send HTML emails with images, links, and style. For the example above one might design email HTML in a separate file and load that into the function with nodes function.

HTML in emails can be complicated. Keep it simple (real simple!) and your emails should render correctly for most people.

Test and receive email

To test your MailJet implementation you can trigger your code with your personal email address as the recipient. If you receive an email you know that your code works. But how do we add this type of test to our automated test suite?

MailSlurp is a service that lets you generate email addresses in code and then receive test emails with them. It has an official Node library so let's use that.

First you need to sign up and get an API Key. mailslurp api key

Now lets add the MailSlurp client as a dependency .

In your tests first create a MailSlurp client.

Then create a new email address.

Now invoke your MailJet sending function with the address you created

By integrating the code above into our application's test suite we can end to end test email sending by capturing the results with MailSlurps test email accounts.