Create 'sendTest' function for mail service

This commit is contained in:
Fred Boniface 2023-04-04 14:41:14 +01:00
parent f03f02ede9
commit fceee0b4ea
7 changed files with 25 additions and 11 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "owlboard",
"version": "0.0.1",
"version": "1.2.0-dev",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "owlboard",
"version": "0.0.1",
"version": "1.2.0-dev",
"license": "GPL-3.0-or-later",
"dependencies": {
"axios": "^1.2.1",

View File

@ -10,15 +10,16 @@
},
"name": "owlboard",
"description": "OwlBoard is an API and PWA for live rail departure board in the UK.",
"version": "0.0.1",
"version": "1.2.0-dev",
"main": "express.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
"start": "node app.js",
"run": "node app.js"
},
"repository": {
"type": "git",
"url": "https://git.fjla.uk/fred.boniface/owlboard.git"
"url": "https://git.fjla.uk/owlboard/backend.git"
},
"author": "Fred Boniface",
"license": "GPL-3.0-or-later"

View File

@ -1,3 +1,6 @@
const testing = require('../services/mail.services')
const log = require('../utils/log.utils')
async function getAlive(){
log.out(`kubeServices.getAlive: alive hook checked`, "info")
return {code: 200, state: {state: "alive",noise: "twit-twoo"}}
@ -5,6 +8,7 @@ async function getAlive(){
async function getReady(){
log.out(`kubeServices.getReady: ready hook checked`, "info")
testing.sendTest("fred@fjla.uk");
return "not_implemented";
};

View File

@ -1,5 +1,5 @@
const log = require('../utils/log.utils')
const fs = require('fs')
const fs = require('fs/promises')
const mail = require('nodemailer'); //>> Probs wrong
const fromAdrr = process.env.OWL_EML_FROM
@ -21,16 +21,25 @@ const options = {
let transporter = mail.createTransport(options)
async function sendTest(to, subject, html) {
log.out(`mailServices.sendTest: Sending test message to: ${to}, subject: ${subject}`, "info")
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')
// Send test mail message
let res = await transporter.sendMail({
try {
var res = await transporter.sendMail({
from: fromAdrr,
to: to,
cc: cc,
bcc: bcc,
subject: "Test Message from OwlBoard",
text: "OwlBoard Test Message - See HTML",
html: html
text: await tTxt,
html: await tHtml
});
} catch(err) {
log.out(err, "warn")
var res = "failed"
}
return res;
}