2023-03-31 21:14:29 +01:00
|
|
|
const log = require('../utils/log.utils')
|
2023-04-04 14:41:14 +01:00
|
|
|
const fs = require('fs/promises')
|
2023-04-04 11:45:32 +01:00
|
|
|
const mail = require('nodemailer'); //>> Probs wrong
|
2023-04-01 11:06:30 +01:00
|
|
|
|
2023-04-01 15:09:29 +01:00
|
|
|
const fromAdrr = process.env.OWL_EML_FROM
|
|
|
|
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 11:45:32 +01:00
|
|
|
// The 'secure' option is set to false as the SMTP server used only supports STARTTLS and will not accept TLS or no encryption
|
2023-03-31 21:14:29 +01:00
|
|
|
|
2023-04-01 15:09:29 +01:00
|
|
|
const options = {
|
|
|
|
host: smtpHost,
|
|
|
|
port: smtpPort,
|
2023-04-04 11:45:32 +01:00
|
|
|
secure: false,
|
2023-04-01 15:09:29 +01:00
|
|
|
auth: {
|
|
|
|
user: smtpUser,
|
|
|
|
pass: smtpPass
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-01 15:11:26 +01:00
|
|
|
let transporter = mail.createTransport(options)
|
2023-04-01 15:09:29 +01:00
|
|
|
|
2023-04-04 14:41:14 +01:00
|
|
|
async function sendTest(to, cc, bcc) {
|
|
|
|
log.out(`mailServices.sendTest: Sending test message to: ${to}`, "info")
|
|
|
|
let tHtml = fs.readFile('mail-templates/test.html', 'utf-8');
|
|
|
|
let tTxt = fs.readFile('mail-templates/test.txt', 'ascii')
|
2023-03-31 21:14:29 +01:00
|
|
|
// Send test mail message
|
2023-04-04 14:41:14 +01:00
|
|
|
try {
|
|
|
|
var res = await transporter.sendMail({
|
2023-04-01 15:09:29 +01:00
|
|
|
from: fromAdrr,
|
|
|
|
to: to,
|
2023-04-04 14:41:14 +01:00
|
|
|
cc: cc,
|
|
|
|
bcc: bcc,
|
2023-04-04 11:45:32 +01:00
|
|
|
subject: "Test Message from OwlBoard",
|
2023-04-04 14:41:14 +01:00
|
|
|
text: await tTxt,
|
|
|
|
html: await tHtml
|
2023-04-01 15:09:29 +01:00
|
|
|
});
|
2023-04-04 14:41:14 +01:00
|
|
|
} catch(err) {
|
|
|
|
log.out(err, "warn")
|
|
|
|
var res = "failed"
|
|
|
|
}
|
2023-04-04 11:45:32 +01:00
|
|
|
return res;
|
2023-04-01 11:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function sendRegister() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendAlert() {
|
|
|
|
return;
|
2023-04-01 15:09:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
sendTest,
|
|
|
|
sendRegister,
|
|
|
|
sendAlert
|
2023-03-31 21:14:29 +01:00
|
|
|
}
|