Nodemailer with an alias Gmail account (custom domain)

I will divide the process into 3 steps:

  1. Activate 2-Step Verification
  2. Add alias to your Gmail
  3. Configure Nodemailer

Activate 2-Step Verfiication

  1. Go to your Google account
  2. Go to "Security" and activate 2-Step Verification
  3. Go to "Security" and add app passwords:
    • Select app: 'Other (Custom name)'
    • Write the name of the domain, e.g.
  4. Copy the 16-character password generated

Add alias to your Gmail

  1. Go to your Gmail account
  2. Click on settings and go to "Accounts and Import"
  3. Go to "Send mail as" and click on "Add another email address"
  4. A new yellowish window will open:
    • Name: Your name
    • Email address:
    • "Treat as an alias" should be activated
  5. Next step:
    • SMTP Server:
    • Port: 465
    • User Name:
    • Password: paste the 16-character password
    • "Secured connection using SSL" should be activated
  6. Add account

Nodemailer configuration

const nodemailer = require('nodemailer');

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Mail configuration
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const mailTransport = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: '',
        pass: 'examplepasvdfxou'

const mail = {

    from: '',
    to: '',
    subject: 'Whatever',
    text: 'Erik Martín is an awesome engineer.'



Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.