Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodemailer, mailer, nodemailer npm

import nodemailer from "nodemailer";

const yourEmail = "yourEmail@gmail.com";
const yourPass = "yourEmailPasswrd";
const mailHost = "smpt.gmail.com";
const mailPort = 587;
const senderEmail = "senderEmail@gmail.com"

/**
 * Send mail
 * @param {string} to 
 * @param {string} subject 
 * @param {string[html]} htmlContent 
 * @returns 
 */
const sendMail = (to, subject, htmlContent) => {
  let transporter = nodemailer.createTransport({
    host: mailHost,
    port: mailPort,
    secure: false, // use SSL - TLS
    auth: {
      user: yourEmail,
      pass: yourPass,
    },
  });
  let mailOptions = {
    from: senderEmail,
    to: to,
    subject: subject,
    html: htmlContent,
  };
  return transporter.sendMail(mailOptions); // promise
};

export default sendMail;



Comment

nodemailer send email

const nodemailer = require("nodemailer");

let transporter = nodemailer.createTransport(
  {
    service: "gmail",
    host: "smtp.gmail.com",
    port: 465,
    auth: {
      user: "userEmail", // generated ethereal user
      pass: process.env.emailPass, // generated ethereal password
    },
  },
  {
    from: "<userEmail>",
  }
);
Comment

how to use nodemailer

const transporter = nodemailer.createTransport({
    host: 'smtp.ethereal.email',
    port: 587,
    auth: {
        user: 'merritt92@ethereal.email',
        pass: 'ZpKpEXzF1P1VFV7HPX'
    }
});
Comment

how to use nodemailer

const transporter = nodeMailer.createTransport({
    host: process.env.SMTP_HOST,
    port: 587,
    secure: false,
    auth: {
      user: process.env.SMTP_MAIL,
      pass: process.env.SMTP_PASSWORD,
    },
  });

  const mailOptions = {
    from: process.env.SMTP_MAIL,
    to: emailUser.email,
    subject: emailUser.subject,
    text: emailUser.message,
  };

  await transporter.sendMail(mailOptions);
Comment

PREVIOUS NEXT
Code Example
Javascript :: usereducer react js 
Javascript :: react usereducer 
Javascript :: how to add number in string in javascript 
Javascript :: build url query string javascript 
Javascript :: moment.add 
Javascript :: how to make fake binary 
Javascript :: javascript merge arrays of objects without duplicates 
Javascript :: assign array to another array javascript 
Javascript :: upload image to firebase 
Javascript :: get id of an element 
Javascript :: Return the average of the given array rounded down to its nearest integer. 
Javascript :: multiply arrays javascript 
Javascript :: add parameters ajax request 
Javascript :: react native float upto 2 digits 
Javascript :: how to design an api node js 
Javascript :: how to clear node modules folder from your computer 
Javascript :: JS toString adds backslash 
Javascript :: adding background video angular 6 
Javascript :: remove repetition 2d array javascript 
Javascript :: django ajax body to json 
Javascript :: javascript append array to array 
Javascript :: match the pattern in the input with javascript 
Javascript :: remove duplicate value from string 
Javascript :: js copy paragraph onclick 
Javascript :: check time javascript 
Javascript :: initialize function in javascript 
Javascript :: open folder node js 
Javascript :: javascript check if property exists in object 
Javascript :: jquery: select select box rpogramatically 
Javascript :: how to link js and a html file in vscode 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =