mirror of
https://github.com/kevin-DL/complete-node-bootcamp.git
synced 2026-01-12 03:15:12 +00:00
28 lines
642 B
JavaScript
28 lines
642 B
JavaScript
const nodemailer = require('nodemailer');
|
|
|
|
const sendEmail = async options => {
|
|
// 1) Create a transporter
|
|
const transporter = nodemailer.createTransport({
|
|
host: process.env.EMAIL_HOST,
|
|
port: process.env.EMAIL_PORT,
|
|
auth: {
|
|
user: process.env.EMAIL_USERNAME,
|
|
pass: process.env.EMAIL_PASSWORD
|
|
}
|
|
});
|
|
|
|
// 2) Define the email options
|
|
const mailOptions = {
|
|
from: 'Jonas Schmedtmann <hello@jonas.io>',
|
|
to: options.email,
|
|
subject: options.subject,
|
|
text: options.message
|
|
// html:
|
|
};
|
|
|
|
// 3) Actually send the email
|
|
await transporter.sendMail(mailOptions);
|
|
};
|
|
|
|
module.exports = sendEmail;
|