npm install --save nodemailer
npm install --save nodemailer-sendgrid-transport

Builind own mailserver is very complex task, thats why we use some existing services for this. We will use Sendgrid (www.sendgrid.com) for this as they have free plan. We need to install also nodemailer and nodemailer-sendgrid-transport.



controllers/auth.js

const nodemailer = require('nodemailer');
const sendgridTransport = require('nodemailer-sendgrid-transport');

const transporter = nodemailer.createTransport(sendgridTransport({
    auth: {
        api_key: SENDGRID_API_KEY
    }
}));




exports.postSignup = (req, res, next) => {
   ...
    transporter.sendEmail({
                to: email,
                from: 'shop@node-complete.com',
                subject: 'New account registration',
                html: '<h1>You successfully signed up !</h1>'
            });
   ...
}