Making an SMTP client

The smtp-protocol module can be used for creating clients too, so let's make a client and use it alongside our SMTP server from the main recipe.

Let's copy the smtp-server folder, naming the duplicate smtp-client.

We don't need to install any new dependencies, so let's simply clear the contents of index.js and open it in our favorite editor.

Let's start by requiring the dependencies:

const os = require('os') const readline = require('readline') const smtp = require('smtp-protocol') 

We're going to use the core readline module as a user interface, creating an interactive shell for sending mail. Let's create a readline interface instance:

const rl = readline.createInterface({   input: process.stdin,  output: process.stdout, ...

Get Node Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.