zoho smtp mail nodejs

Step 1: Install the required Node.js modules using npm:

npm install nodemailer

Step 2: Import the nodemailer module and create a transporter using Zoho SMTP settings:

const nodemailer = require('nodemailer');

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

Step 3: Compose the email message with required details:

const mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Subject of the email',
  text: 'This is the plain text body of the email',
  html: '<p>This is the HTML body of the email</p>',
};

Step 4: Send the email using the transporter and mail options:

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

Note: Replace '[email protected]', 'your_zoho_email_password', and '[email protected]' with your Zoho email, Zoho email password, and the recipient's email address respectively. Adjust other details such as subject, text, and html as needed. Ensure that the 'nodemailer' module is installed using the 'npm install nodemailer' command before running the script.