The Fundamentals (Node.js, SMTP & Nodemailer)
Email has become an ubiquitous part of modern applications. As a primary communication channel, nearly every user interaction, from password resets to transaction receipts, triggers an automated email message.
In this module, we'll explore electronic mails (email), their lifecycle, and the protocols that carry them from the senders client to the receivers inbox and choices you face as a developer to implement one that scale in Node and NestJS.
What is email?
Electronic mail is commonly shortened to "email". It is a communication method that uses electronic devices to deliver messages across network of computers. Email isn't restricted to internet, in fact it existed long before it. It history can be traced to the 1970s when a programmer Ray Tomlinson built a way to transmit messages over Advanced Research Projects Agency Network (ARPANET) long before TCP/IP in fact.
The 6 pillars of email delivery
Email as it is today passes through multiple servers, similar to how traditional letters goes through multiple postal offices before reaching its final destination. The email ecosystem relies on six critical components I call pillars. Much like a physical postal service, there is a lot happening before your letter or item reaches the intended recipient.
- Mail User Agent (MUA),commonly known as the email client (Google Gmail, Microsoft Outlook, Mozilla Thunderbird) is the interface where the sender composes the message before being sent to a sender's email server.
- Mail Submission Agent (MSA) is a crucial component of email delivery. The software does three (3) things: accepts the mail from the MUA, validate & checks for errors before sending mail to the MTA.
- Mail Transfer Agent (MTA) is responsible for the actual transfer of email messages between servers. It routes the email across the internet to the recipient's server.
- Receiving MTA is the destination server that accepts the incoming message.
- Mail Delivery Agent (MDA) is the "local carrier" that places the message into the recipient's specific mailbox ( Receivers Mail User Agent).
- IMAP/POP3 Protocols: The tools the recipient uses to retrieve the mail from the mailbox.
These components can be further categorized into two
- Email Infrastructure: user agents, servers, mailboxes
- SMTP: simple mail transfer protocol
We won't go into details with MSAs, MTAs. However, this article will be incomplete without discussing in details some of the protocols used for sending emails.
Understanding SMTP
SMTP (Simple Mail Transfer Protocol) is a one way protocol used for sending email only (not responsible for receiving email) that sits on top of TCP. Think of it as a one way post office for your emails. They can send them but not receive them. It's important to add that unlike other TCP meta-protocols like HTTP that pulls data from a server, SMTP pushes data to a server or between servers.
To complete the loop, SMTP hands off the message to the MDA, where protocols like IMAP or POP3 allow the end-user to access these messages in their inboxes.
While SMTP remains the backbone of email, many modern developers are shifting toward HTTP-based APIs (like SendGrid or Postmark). These offer better security (hiding your server's IP), easier credential management, and built-in analytics that raw SMTP lacks.
Parts of an email
Email is broadly divided into three parts:
- The SMTP Envelope
This is the part you do not see. It is an invisible wrapper around your email message that primarily contains the sender's and the receiver's address(es)MAIL FROM, RCPT TOjust like we write addresses on the physical copies of a letter in post offices. While The SMTP Envelope often shares data with the message header, Eit is generated by the mail client like email provider and mail servers, and could contain other details like size of email body, delivery status notification etc. - The Header
This is top of your body email where you provideTo,From,Subject,Cc,BccandDate. Because you provided a receiver's (and yours, the sender's) here do not mean it will appear the same on the SMTP Envelope. Aside mail servers having the ability to override an Envelope, malicious users can.
For example, your email could readtoas johndoe@gmail.com but a malicious users could wrapJOhndoe@mail.comaround the Envelope instead. - The Body
The body may contain text, images, links, videos, and any other file attachments, provided that they do not exceed the email client's size restrictions. Alternatively, an email can be sent without any information in the body field and formatted as plain text or HTML.
References
Footnotes
- MUA Pasted on Tue, March 03, 2026.
- What is an Email Pasted on Sunday, March 03, 2026.