How to test EmailJS

12th Mar 2023

Share this article:

EmailJS is an email service designed to make sending email from JavaScript easy, without requiring any server side code.

It lets you configure many popular email service providers, generate an email template and then use their JavaScript SDK to send email direct from your front end.

Why would I test my emails during development?

When you're building and testing software you need a solution for "faking" the email sending part of your software. You need to test that emails get sent at the right time, that they're content is great and that they'll actually get delivered.

Ideally, you want to use the same EmailJS SDK when you're building and testing your software but you don't want to be sending actual emails, as that makes it more likely that you'll accidentally send real emails. Just ask HBO:

Picture of Tweet from HBO apologising for mass email

How can I do this for EmailJS?

For development/test you will want to use a fake email service for EmailJS. It's easy to set up as you specify the EmailJS email service ID when sending your emails. This makes it very easy to add a configuration setting that allows you to specify your test email service id in development and then your "real" production email service id when live.

Why use Imitate Email as your fake email service

Imitate Email lets you test your email sending whilst developing and testing your software. It provides a fake SMTP server, a web app and a web widget for testing email flows as well as providing tools to ensure your emails look great and get delivered.

With EmailJS, you're likely building a web application: Imitate Email provides an embedded web widget that you can embed in your web app using a single line of JavaScript. You can then easily see when emails are sent from your web application as they'll show up in your application as you build.

Setting up the Imitate Email service

Once, you've signed up for Imitate Email you will be provided with your SMTP settings for your personal mailbox.

Now, go to the EmailJS services page and click "Add New Service":

Picture of Add New Service in EmailJS

Then, under Personal Services, choose SMTP Server:

Picture of Personal Services in EmailJS

Then, fill in the details as shown in this image, making sure you add your own username/password for your Imitate Email mailbox:

Picture of SMTP Settings in EmailJS

Note that we use STARTTLS to encrypt your traffic, not SSL - so don't tick the Use SSL box, we automatically upgrade the connection to an encrypted one.
Also, don't tick "Send test email to verify configuration" as it won't work (see their info box for more)

When setting up your email template, make sure that you specify a from email address, collected from your form:

Picture of From Email in EmailJS

Lastly, make sure you specify the correct service id in the JavaScript SDK when sending email:

emailjs.sendForm('<your service id>', '<your template id>', this)

That's it. Send your emails using EmailJS and test them using Imitate Email.