DEV Community

Cover image for Working with Nodemailer and MailHog

Posted on

Working with Nodemailer and MailHog

This week developers at Seneca College have been working hard to add more features and functionalities to Starchart. With the release of version 0.2, I got to experiment with MailHog; tool developers used to test sending and receiving emails in a development environment using a fake SMTP server. Another cool thing is you don't need an actual recipient or sender account to use Mailhog. I like Mailhog because you do not have to install it locally. Pulling the Mailhog docker image and building the container will give the developer access to a friendly UI similar to that of Google or Outlook.

The Fun Part

The exciting part was sending test emails using the sendNotifications I contributed to and having them appear in real-time in the Mailhog UI.

The Tough Part

The challenging part was writing unit tests for Nodemailer using Vitest/Jest API. Fetching messages sent to the recipient using the endpoint returns a deeply nested object. I had to end up using to expect functions such as arrayContaining and objectContaining in conjunction to ignore fields that were not relevant to the test suite.

Up Next

This week I intend on implementing functionality for sending email notifications when a domain becomes active or errors using BullMQ workers queues. Also, working with BullMQ may prove challenging, but I want to give it a shot, as I would gain valuable experience. Another goal is to update the Dependabot configuration to avoid non-LTS node version updates. Also, since I am one of the Sheriffs this week, I intend to be highly available if any problems require prompt attention.

Oldest comments (0)