Chapter 11. Sending Email
One of the primary ways your application can communicate with the world is email. From user registration to password reset instructions to promotional emails, the ability to send email is an important feature. In this chapter, you’ll learn how to format and send email with Node and Express to help communicate with your users.
Neither Node nor Express has any built-in way of sending email, so we have to use a third-party module. The package I recommend is Andris Reinman’s excellent Nodemailer. Before we dive into configuring Nodemailer, let’s get some email basics out of the way.
SMTP, MSAs, and MTAs
The lingua franca for sending email is the Simple Mail Transfer Protocol (SMTP). While it is possible to use SMTP to send an email directly to the recipient’s mail server, this is generally a bad idea: unless you are a “trusted sender” like Google or Yahoo!, chances are your email will be tossed directly into the spam bin. It’s better to use a mail submission agent (MSA), which will deliver the email through trusted channels, reducing the chance that your email will be marked as spam. In addition to ensuring that your email arrives, MSAs handle nuisances like temporary outages and bounced emails. The final piece of the equation is the mail transfer agent (MTA), which is the service that actually sends the email to its final destination. For the purposes of this book, MSA, MTA, and SMTP server are essentially equivalent.
So you’ll need access to an MSA. While ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access