Started work on migration UI. Improved email handling.
This commit is contained in:
parent
bddbd9cd36
commit
eb48b92551
9 changed files with 252 additions and 23 deletions
|
|
@ -173,10 +173,10 @@ module.exports.errorMiddleware = function(err, req, res, next){
|
|||
* @param {Error} err - error to dump to file
|
||||
* @param {Date} date - Date of error, defaults to now
|
||||
*/
|
||||
module.exports.dumpError = async function(err, date = new Date()){
|
||||
module.exports.dumpError = async function(err, date = new Date(), subDir){
|
||||
try{
|
||||
//Crash directory
|
||||
const dir = "./log/crash/"
|
||||
const dir = `./log/crash/${subDir}`
|
||||
|
||||
//Double check crash folder exists
|
||||
try{
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ const config = require('../../config.json');
|
|||
|
||||
//NPM imports
|
||||
const nodeMailer = require("nodemailer");
|
||||
const validator = require('validator');
|
||||
|
||||
//local imports
|
||||
const loggerUtils = require('./loggerUtils');
|
||||
|
||||
|
||||
//Setup mail transport
|
||||
/**
|
||||
|
|
@ -43,28 +48,38 @@ const transporter = nodeMailer.createTransport({
|
|||
* @returns {Object} Sent mail info
|
||||
*/
|
||||
module.exports.mailem = async function(to, subject, body, htmlBody = false){
|
||||
//Create mail object
|
||||
const mailObj = {
|
||||
from: `"Tokebot🤖💨"<${config.mail.address}>`,
|
||||
to,
|
||||
subject
|
||||
};
|
||||
try{
|
||||
//If we have a bad email address
|
||||
if(!validator.isEmail(to)){
|
||||
//fuck off
|
||||
return;
|
||||
}
|
||||
|
||||
//If we're sending HTML
|
||||
if(htmlBody){
|
||||
//set body as html
|
||||
mailObj.html = body;
|
||||
//If we're sending plaintext
|
||||
}else{
|
||||
//Set body as plaintext
|
||||
mailObj.text = body
|
||||
//Create mail object
|
||||
const mailObj = {
|
||||
from: `"Tokebot🤖💨"<${config.mail.address}>`,
|
||||
to,
|
||||
subject
|
||||
};
|
||||
|
||||
//If we're sending HTML
|
||||
if(htmlBody){
|
||||
//set body as html
|
||||
mailObj.html = body;
|
||||
//If we're sending plaintext
|
||||
}else{
|
||||
//Set body as plaintext
|
||||
mailObj.text = body
|
||||
}
|
||||
|
||||
//Send mail based on mail object
|
||||
const sentMail = await transporter.sendMail(mailObj);
|
||||
|
||||
//return the mail info
|
||||
return sentMail;
|
||||
}catch(err){
|
||||
loggerUtils.dumpError(err, new Date(), 'mail/');
|
||||
}
|
||||
|
||||
//Send mail based on mail object
|
||||
const sentMail = await transporter.sendMail(mailObj);
|
||||
|
||||
//return the mail info
|
||||
return sentMail;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue