zoho smtp mail nodejs

Zoho SMTP Mail with Node.js

If you are developing a web application with Node.js and need to send emails, you can use Zoho SMTP mail service. Zoho provides secure SMTP server settings to send emails from your application. Here is how you can configure Zoho SMTP mail with Node.js:

Step 1: Create a Zoho Mail Account

If you don't have a Zoho mail account, create one by visiting https://www.zoho.com/mail/. Once you have created your account, log in to your Zoho account.

Step 2: Generate an App Password

To send emails using the SMTP server, you need to generate an app password. To generate an app password, follow these steps:

  1. Go to Zoho Mail Control Panel -> Mail Accounts.
  2. Select the email account for which you want to generate the app password.
  3. Click on the Generate New Password button.
  4. Enter a name for the app password and click on the Generate button.
  5. Note down the app password, as it will be required later in your Node.js application.

Step 3: Install Nodemailer Module


npm install nodemailer

Step 4: Configure Nodemailer with Zoho SMTP Settings

Now, you need to configure the Nodemailer module with your Zoho SMTP settings. Here's the code:


const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
  host: 'smtp.zoho.com',
  port: 465,
  secure: true,
  auth: {
    user: '[email protected]',
    pass: 'your-app-password'
  }
});

Replace [email protected] with your Zoho email address and your-app-password with the app password you generated in step 2.

Step 5: Send Email


let mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Test Email',
  text: 'This is a test email from Node.js using Zoho SMTP.'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

Replace [email protected] with your Zoho email address and [email protected] with the email address of the recipient.

Alternative Method: Use Zoho SMTP Relay

If you face any issues with the above method, you can use Zoho SMTP relay to send emails. Here's how:

  1. Go to Zoho Mail Control Panel -> SMTP/IMAP.
  2. Select Add SMTP Relay button.
  3. Enter a name for the SMTP relay and click on the Add button.
  4. Note down the SMTP relay details, as it will be required later in your Node.js application.

Follow steps 3 to 5 using the following code:


let transporter = nodemailer.createTransport({
  host: 'your-smtp-relay.zoho.com',
  port: 587,
  secure: false,
  auth: {
    user: '[email protected]',
    pass: 'your-zoho-password'
  }
});

Replace your-smtp-relay.zoho.com with the SMTP relay details you noted down in step 3 and your-zoho-password with your Zoho mail account password.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe