backend/src/services/mail.services.js

35 lines
1017 B
JavaScript
Raw Normal View History

const log = require('../utils/log.utils')
2023-04-04 11:45:32 +01:00
const mail = require('nodemailer'); //>> Probs wrong
const fromAddr = process.env.OWL_EML_FROM
2023-04-01 15:09:29 +01:00
const smtpUser = process.env.OWL_EML_USER
const smtpPass = process.env.OWL_EML_PASS
const smtpHost = process.env.OWL_EML_HOST
const smtpPort = process.env.OWL_EML_PORT
2023-04-04 17:17:12 +01:00
let transporter = mail.createTransport({
2023-04-01 15:09:29 +01:00
host: smtpHost,
port: smtpPort,
2023-04-04 17:17:12 +01:00
secure: false, // Must be false for STARTTLS on port 587
2023-04-01 15:09:29 +01:00
auth: {
user: smtpUser,
pass: smtpPass
}
2023-04-04 17:17:12 +01:00
})
2023-04-01 15:09:29 +01:00
async function send(message){ // message is an object containing strings for: *to, cc, bcc, *subject, *txt, html (* denotes required)
log.out(`mailServices.send: Message send request received`, "info")
message.from = fromAddr
try {
var res = await transporter.sendMail(message)
} catch(err) {
log.out(`mailServices.send: Message send failed`, "err")
return false;
}
log.out(`mailServices.send: SMTP Response: ${res.response}`)
return true;
2023-04-01 15:09:29 +01:00
}
module.exports = {
send
}