games-express-api/utils/sendEmail.js

31 lines
921 B
JavaScript
Raw Normal View History

2024-09-12 15:48:27 -04:00
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