Refactor nodemailer config

This commit is contained in:
2020-09-01 18:34:33 +02:00
parent 4579be1541
commit 3490f71fc3
7 changed files with 62 additions and 28 deletions

View File

@@ -0,0 +1,15 @@
const transporter = require('./transporter');
transporter.sendMail(message, (error, info) => {
if (error) {
console.log('Error occurred');
console.log(error.message);
return process.exit(1);
}
console.log('Message sent successfully!');
console.log(nodemailer.getTestMessageUrl(info));
// only needed when using pooled connections
transporter.close();
});

View File

@@ -2,7 +2,7 @@ module.exports = {
appURL: 'https://meetingplanner.com',
sender: 'no-reply@ruihildt.xyz',
receiver: 'ruihildt@armada.digital',
receiver: 'rui@armada.digital',
senderUsername: 'Rui',
meetingTitle: 'Simple Title meeting',

View File

@@ -7,7 +7,7 @@ const {
meetingID,
signature,
appURL,
} = require('../emailConfigs');
} = require('../tempConfig');
let meetingInvite = {
from: sender,

View File

@@ -0,0 +1,41 @@
const nodemailer = require('nodemailer');
const {
smtpPool,
smtpHost,
smtpPort,
smtpUsername,
smtpPassword,
smtpSecure,
smtpRequireTLS,
} = require('../../config/config');
let mailConfig;
if (process.env.NODE_ENV === 'production') {
// all emails are delivered to destination
mailConfig = {
pool: smtpPool,
host: smtpHost,
port: smtpPort,
requireTLS: smtpRequireTLS,
secure: smtpSecure,
auth: {
user: smtpUsername,
pass: smtpPassword,
},
};
} else {
// all emails are catched by ethereal.email
// Check test emails: https://ethereal.email/login
mailConfig = {
host: 'smtp.ethereal.email',
port: 587,
auth: {
user: 'lemuel.wunsch91@ethereal.email',
pass: 'Y9Vs51v27Q9X9feJgN',
},
};
}
module.exports = nodemailer.createTransport(mailConfig);