Ethereal email testing

Today I’m really excited to announce the release of Nodemailer v4.1.0. If you have everything already set up regarding email sending then you probably do not care too much about this release. If you are currently building something or plan to build an app that, amongst other things, sends email, then this new release might interest you.

Nodemailer v4.1.0 includes 2 new API methods

nodemailer.createTestAccount(callback)

and

nodemailer.getTestMessageUrl(info)

where the first one generates an actually working email account out of the blue and the other one returns extra information about a delivery.

These autogenerated accounts are not too real though, these are test accounts from Ethereal.email mail testing service.

When an Ethereal test account is used then Nodemailer establishes a normal SMTP connection against Ethereal SMTP server, authenticates with actual credentials and the server accepts message for delivery, so nothing unusual about it. What is a bit unusual though is that the Ethereal server never does the actual delivery, it stores the message to the account of the authenticated user and that’s it. You don’t have to worry about unexpected deliveries where mail is delivered to actual recipients. Ethereal never sends any messages.

Finally, the getTestMessageUrl(info) method returns a web URL that can be used to preview the sent message in a browser.  You can preview the message HTML, download the RFC822 source of the message or just check the message headers.

You can store the autogenerated credentials and start using these as development credentials instead of spamming a real email account. Or if you do not want to then you can generate fresh credentials for every new test email, it’s your own choice.  If you want to use IMAP to preview the sent messages then you probably want to use pre-generated credentials, otherwise it wouldn’t make much sense.

6 Replies to “Ethereal email testing”

  1. I’ve been using the createTestAccount method to send with ethereal.email in automated mocha testing, where I then retrieve the email via smtp to check the contents. The first test in the block runs great! — but subsequent tests fail because createTestAccount uses the same account again, instead of generating a fresh one. I’ve made sure I’m opening and closing the server fresh for each test. Any ideas?

    1. Cached accounts is kind of intentional. Why do your tests fail? Can’t you use the already existing account? In mocha you can use a beforeAll() method to create the account and cache credentials and then reuse the same credentials in all your tests.

  2. I guess that will work for my needs, if I retrieve all messages in the box each time with POP and sort for the newest. The POP clients I’ve found all seem to retrieve the oldest mail first with no obvious options to change that… do you know way to get the newest first? With a static ethereal address I was hitting a timeout in mocha at 10 seconds because I couldn’t retrieve and sort fast enough. Could be a problem with createTestAccount if there are too many tests in a block.

    1. Maybe you should consider using an IMAP client instead of POP client as IMAP gives you much better options for fetching and searching messages?

      If you do need to use POP or you really need to get fresh accounts, then you can bypass Nodemailer and fetch a new account by yourself. It’s a simple HTTP API call:

      curl -XPOST https://api.nodemailer.com/user -H 'content-type: application/json' -d '{
          "requestor": "yourapp name",
          "version": "your.app.version"
      }'
  3. i want to know that nodemailer email service is free for lifetime or restricts to some number of emails ? please reply immediately, its urgent for me.

    1. It is free as long as the usage does not affect the stability of the service. If you send so many emails that the server is not able to accept these for a longer period then your IP might get blocked. Otherwise there are no limitations on place.

Leave a Reply

Your email address will not be published. Required fields are marked *