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;
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>",
}
);
const transporter = nodemailer.createTransport({
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: 'merritt92@ethereal.email',
pass: 'ZpKpEXzF1P1VFV7HPX'
}
});
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);