Send email with nodemailer and Zoho mail SMTP

14 February 2022
An alternative to SendGrid
node.js

Today I learned that I can send email with Zoho mail SMTP in my node.js application. Previously I am using SendGrid and decided to browse for alternative, and figured that Zoho mail SMTP is as simple as sending email with SendGrid.


Let's send that email!

  1. Add nodemailer to your node application
yarn add nodemailer
  1. Import and start sending email
const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: "smtp.zoho.com",
  secure: true,
  port: 465,
  auth: {
    user: "[email protected]",
    pass: process.env.ZOHO_APP_PASSWORD,
  },
});
const msg = {
  to: email,
  from: '[email protected]', // Change to your verified sender
  subject: 'Your receipt',
  text: 'Thank you for purchasing with us.',
  html: emailTemplate, // html string or ejs template
}

transporter.sendMail(msg, function(error, info) {
  // handler
});

For the password, it is recommended to use Zoho app password. It works with two-factor authentication enabled for your Zoho account, and is easier to manage in case it is compromised.

That's it!

Hope that helps.

Cheers.