Save time managing and deploying your node.js app. Code faster with jitsu and npm

Node Mailer Redux

About the author

nodejitsu nodejitsu

At NodeJitsu we know how important it is to build quality open-source software and when there is a problem with one of our projects, we want to fix it.
We also know that often the right solution involves reaching out to the community and helping contribute to other people's libraries.
When we found out there were bugs in our STMP client library, node_mailer, we wanted to find what was best for both ourselves and the community.
We decided to research the current landscape for node.js mailers and try to make an informed descision.
Since our library is mostly concerned with creating an easy API for sending mail, we wanted to look at alternative solutions for a solid SMTP implementation.

In this article I will discuss our approach for fixing the node_mailer library and how we actually helped fix issues in another mailer project along the way.


First we evaluated many of the modules at hand that are commonly used for mailing (funny enough, there are several modules matching /node[-_]?mailer/i).
There were various issues with each project and none of the other projects supported the full feature set we wanted for sending emails.
We had to make a hard choice: Rewrite our entire node_mailer project ( which would have taken a lot of development hours ) or abandon it ( which would leave 100s of developers without a working library ).
After further reasearch we realized there was a third option: Apply patches to another mailer project, then use this as a dependency for our mailer.
We could get the functionality we wanted with minimal work and help improve someone else's project.
We considered this approach the best, both for ourselves and for the community as a whole.


We ended up choosing to use NodeMailer as a dependency because it was feature rich, mature, extensible, and easy to use.
It was also recommended in this poignant node_mailer issue.
NodeMailer is inspired by Google's Mail Python API library and has very nice documentation.
Also, NodeMailer uses a pipelined state callback letting us easily hook both before and after events while extending it.
For those of you out there who use unicode in your account info, it supported UTF-8! Amazingly, the turnaround time on tickets that were reproducible bugs was around a day.
This library was looking very good.

But, there were some downsides:

  • NodeMailer did not support StartTLS.
  • We couldn't queue up multiple messages.

So, it was decided to kick some bug ass and get those 2 issues resolved.

Thanks to TooTallNate's example floating around we were able to get StartTLS going in short order.

For message queueing we had to dig a bit deeper.
The SMTP logic was in both the SMTPClient and Message interfaces.
If we wanted robust queueing we would need to put it all in one place unless we wanted to spawn up entirely new clients as a queue (yikes!).
So, that bug too was defeated handily.
For now though, that lives alone in node_mailer.
We will get that pushed out to NodeMailer once we get some design stuff ironed out.

Along the way we had some minor fixes for some SMTP reply codes, a parser bug that would only occur in very edgy situations, and a whole lotta kicking ass.

The new fine tuned nodemailer on Github is working better than ever and feels good to use.
We were able to fix the problems we had with our node
mailer library and help patch up NodeMailer.
Both libraries are better now and it's a win for the node community.


There are still a few things to do to make this module something we can call the definitive answer to Node's emailing needs.
Hopefully, the community can work with us to get a couple more features bore into Nodemailer to make it better than ever!
If you want to get started head on over to the github issues for Nodemailer, and the node_mailer you know and love will get them downstream.