|
|
|
@ -1,11 +1,13 @@
|
|
|
|
|
import Settings, { SETTINGS_FILE } from '../../data/Settings';
|
|
|
|
|
var express = require('express');
|
|
|
|
|
var router = express.Router();
|
|
|
|
|
var nodemailer = require('nodemailer');
|
|
|
|
|
var mg = require('nodemailer-mailgun-transport');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const pug = require('pug');
|
|
|
|
|
router.post('/', function(req, res) {
|
|
|
|
|
fs.readJson('config/site-settings.json')
|
|
|
|
|
const settings = new Settings();
|
|
|
|
|
router.post('/', function (req, res) {
|
|
|
|
|
settings
|
|
|
|
|
.load(SETTINGS_FILE)
|
|
|
|
|
.then(settings => {
|
|
|
|
|
let transport = '';
|
|
|
|
|
var auth = '';
|
|
|
|
@ -17,8 +19,8 @@ router.post('/', function(req, res) {
|
|
|
|
|
secure: false,
|
|
|
|
|
auth: {
|
|
|
|
|
type: 'login',
|
|
|
|
|
email: settings.email.smtp,
|
|
|
|
|
password: settings.email.smtp.password
|
|
|
|
|
user: settings.email.smtp,
|
|
|
|
|
pass: settings.email.smtp.password
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
transport = nodemailer.createTransport(auth);
|
|
|
|
@ -26,33 +28,32 @@ router.post('/', function(req, res) {
|
|
|
|
|
case 'option-mg':
|
|
|
|
|
auth = {
|
|
|
|
|
auth: {
|
|
|
|
|
api_key: settings.email.mailgun['api-key'],
|
|
|
|
|
api_key: settings.email.mailgun.key,
|
|
|
|
|
domain: settings.email.mailgun.domain
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
transport = nodemailer.createTransport(mg(auth));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
let render = pug.compileFile('themes/dash/email/base.pug');
|
|
|
|
|
let render = pug.compileFile('brain/views/email/base.pug');
|
|
|
|
|
let html = render({
|
|
|
|
|
title: settings.title,
|
|
|
|
|
header: 'a note from ' + settings.title,
|
|
|
|
|
title: settings.global.title,
|
|
|
|
|
header: 'a note from ' + settings.global.title,
|
|
|
|
|
content: req.body.content,
|
|
|
|
|
footer: 'powered by fipamo'
|
|
|
|
|
});
|
|
|
|
|
transport.sendMail(
|
|
|
|
|
{
|
|
|
|
|
from: 'control@playvico.us',
|
|
|
|
|
to: 'are0h@protonmail.com', // An array if you have multiple recipients.
|
|
|
|
|
to: req.session.user.email, // An array if you have multiple recipients.
|
|
|
|
|
subject: 'Hey beautiful',
|
|
|
|
|
//You can use "html:" to send HTML email content. It's magic!
|
|
|
|
|
html: html
|
|
|
|
|
//You can use "text:" to send plain-text content. It's oldschool!
|
|
|
|
|
//text: 'Mailgun rocks, pow pow!'
|
|
|
|
|
},
|
|
|
|
|
function(err, info) {
|
|
|
|
|
function (err, info) {
|
|
|
|
|
if (err) {
|
|
|
|
|
//console.log(err);
|
|
|
|
|
res.json({
|
|
|
|
|
message: 'MAIL ERROR',
|
|
|
|
|
desc: err
|