games-express-api/utils/sendEmail.js

31 lines
921 B
JavaScript

import nodemailer from 'nodemailer'
import yn from 'yn'
const sendEmail = async options => {
const transporter = nodemailer.createTransport({
host: Bun.env.SMTP_HOST,
port: Bun.env.SMTP_PORT,
secure: yn(Bun.env.SECURE), // true for 465, false for other ports
auth: {
user: Bun.env.SMTP_USER, // generated ethereal user
pass: Bun.env.SMTP_PASSWORD, // generated ethereal password
},
})
// send mail with defined transport object
const message = {
from: `${Bun.env.FROM_NAME} <${Bun.env.FROM_EMAIL}>`, // sender address
to: options.email, // list of receivers
subject: options.subject, // Subject line
html: options.message.html, // HTML body
text: options.message.text, // plain text body
}
const info = await transporter.sendMail(message).catch((err) => console.error(err))
console.log('Message sent: %s', info.messageId)
}
export default sendEmail