Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

npm install nodemailer

npm i nodemailer
Comment

send mail, nodemailer, 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 hook 
Javascript :: get option value jquery 
Javascript :: How to add Strings as numbers in JavaScript 
Javascript :: create url with query parameters javascript 
Javascript :: linking html with javascript 
Javascript :: No provider for ReducerManager 
Javascript :: js date in two weeks 
Javascript :: javascript explode space 
Javascript :: javascript class methods 
Javascript :: js array from 
Javascript :: how to check password and confirm passwor in joi 
Javascript :: puppeteer headless 
Javascript :: open modal useState 
Javascript :: webpack error cannot find module 
Javascript :: remove undefined element from array 
Javascript :: javascript remove all element in array 
Javascript :: javascript return object property from array 
Javascript :: mongodb mongoose aggregate two collections using lookup & format the result set. 
Javascript :: remove repetition multidimensional array javascript 
Javascript :: vuetify autocomplete get input value 
Javascript :: js add array to array 
Javascript :: js length of longest array in 2d array 
Javascript :: check type of variable in javascript 
Javascript :: select distinct on expressions must match initial order by expressions django 
Javascript :: image react native 
Javascript :: binary tree implementation javascript 
Javascript :: debouncing 
Javascript :: Uncaught (in promise) ReferenceError: React is not defined 
Javascript :: Print array of objects js 
Javascript :: javascript string ends with 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =