Sending Custom Email using Nodemailer Nodejs

admin Avatar
const nodemailer = require("nodemailer");

// async..await is not allowed in global scope, must use a wrapper
async function main() {
  // Generate test SMTP service account from
  // Only needed if you don't have a real mail account for testing
  let testAccount = await nodemailer.createTestAccount();

    const transporter = nodemailer.createTransport({
        host: '',
        port: 465,
        auth: {
            user: '', // generated ethereal user
            pass: 'qW$=5!xfghgghfg6a+{b', // generated ethereal password


  // send mail with defined transport object
  let info = await transporter.sendMail({
      from: "",
    to: ",", // list of receivers
    subject: "Hello nodeJS Email  ✔", // Subject line

    text: "Hello world works today", // plain text body
    html: "<style>.df{color:#ccc; text-align:center; background:#333; margin:50px; padding:100px;}</style><div><h1 class='df'>Hello Now Test 07:10</h1></div>", // html body

  console.log("Message sent: %s", info.messageId);
  // Message sent: <>

  // Preview only available when sending through an Ethereal account
  console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
  // Preview URL:


Tagged in :

admin Avatar

More Articles & Posts