Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

const nodemailer = require("nodemailer");

let email = ""
let send_to = ""

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: "", // generated ethereal user
pass: "", // generated ethereal password
},
});


var mailOptions = {
from: email,
to: send_to,
subject: 'Sending Email using Node.js',
text: '<h1>TEST DESH!!</h1>'
};

transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Comment

nodemailer

npm install nodemailer
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

nodemailer

yarn add nodemailer
Comment

nodemailer

var smtpTransport = require('nodemailer-smtp-transport');

var transport = nodemailer.createTransport(smtpTransport({
    service: 'gmail',
    auth: {
        user: 'myemail@gmail.com', // my mail
        pass: 'mypassword'
    }
}));
Comment

How to Get Started with Nodemailer

node -v 
npm -v
Comment

PREVIOUS NEXT
Code Example
Javascript :: upload file react onclick 
Javascript :: javascript combining arrays 
Javascript :: @angular-devkit/build-angular <error 
Javascript :: start date time picker from day to year in html 
Javascript :: event after div created 
Javascript :: nds npm 
Javascript :: react typescript set type 
Javascript :: start live server react js 
Javascript :: jquery syntax 
Javascript :: middleware in node js 
Javascript :: luxon plus 
Javascript :: current date jquery and current day 
Javascript :: js string to arraybuffer 
Javascript :: numeral js 
Javascript :: how to compare previous value with current in javascript 
Javascript :: How To Generate a Table With JavaScript 
Javascript :: current page number and clicked page number jqery datatables 
Javascript :: for loop js 
Javascript :: array limit js 
Javascript :: check if property exists javascript 
Javascript :: copia array javascript 
Javascript :: how to reverse array in javascript 
Javascript :: clean code javascript 
Javascript :: javascript integer to binary 
Javascript :: datatable add filter dropdown 
Javascript :: networkx get nodes 
Javascript :: autocannon 
Javascript :: how to replace all the string in javascript when the string is javascript variable 
Javascript :: check contect type axios response 
Javascript :: nodejs request post 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =