Skip to content
the poor coder

zoho smtp mail nodejs

Poor Man
Published
Reading time
2 min read
On this page

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#

JavaScript

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:

JavaScript

const nodemailer = require('nodemailer');

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

Replace your-email@zoho.com with your Zoho email address and your-app-password with the app password you generated in step 2.

Step 5: Send Email#

JavaScript

let mailOptions = {
  from: 'your-email@zoho.com',
  to: 'recipient-email@example.com',
  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 your-email@zoho.com with your Zoho email address and recipient-email@example.com 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:

JavaScript

let transporter = nodemailer.createTransport({
  host: 'your-smtp-relay.zoho.com',
  port: 587,
  secure: false,
  auth: {
    user: 'your-email@zoho.com',
    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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC