Refactor nodemailer config
This commit is contained in:
parent
4579be1541
commit
3490f71fc3
@ -3,11 +3,14 @@ module.exports = {
|
|||||||
// APP
|
// APP
|
||||||
port: process.env.PORT || 3001,
|
port: process.env.PORT || 3001,
|
||||||
environment: process.env.NODE_ENV || 'development',
|
environment: process.env.NODE_ENV || 'development',
|
||||||
|
|
||||||
// DATABASE
|
// DATABASE
|
||||||
dbURL: process.env.DATABASE_URL,
|
dbURL: process.env.DATABASE_URL,
|
||||||
|
|
||||||
// JWT
|
// JWT
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
saltingRounds: 10,
|
saltingRounds: 10,
|
||||||
|
|
||||||
// NODEMAILER
|
// NODEMAILER
|
||||||
smtpHost: process.env.SMTP_HOST,
|
smtpHost: process.env.SMTP_HOST,
|
||||||
smtpPort: process.env.SMTP_PORT,
|
smtpPort: process.env.SMTP_PORT,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const transporter = require('./smtpConfig');
|
const transporter = require('../services/email/transporter');
|
||||||
|
|
||||||
function logSmtpStatus() {
|
function logSmtpStatus() {
|
||||||
transporter.verify(function (error, success) {
|
transporter.verify(function (error, success) {
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
const nodemailer = require('nodemailer');
|
|
||||||
|
|
||||||
const {
|
|
||||||
smtpPool,
|
|
||||||
smtpHost,
|
|
||||||
smtpPort,
|
|
||||||
smtpUsername,
|
|
||||||
smtpPassword,
|
|
||||||
smtpSecure,
|
|
||||||
smtpRequireTLS,
|
|
||||||
} = require('../config/config');
|
|
||||||
|
|
||||||
const smtpTransporter = nodemailer.createTransport({
|
|
||||||
pool: smtpPool,
|
|
||||||
host: smtpHost,
|
|
||||||
port: smtpPort,
|
|
||||||
requireTLS: smtpRequireTLS,
|
|
||||||
secure: smtpSecure,
|
|
||||||
auth: {
|
|
||||||
user: smtpUsername,
|
|
||||||
pass: smtpPassword,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = smtpTransporter;
|
|
15
services/email/sendEmail.js
Normal file
15
services/email/sendEmail.js
Normal 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();
|
||||||
|
});
|
@ -2,7 +2,7 @@ module.exports = {
|
|||||||
appURL: 'https://meetingplanner.com',
|
appURL: 'https://meetingplanner.com',
|
||||||
|
|
||||||
sender: 'no-reply@ruihildt.xyz',
|
sender: 'no-reply@ruihildt.xyz',
|
||||||
receiver: 'ruihildt@armada.digital',
|
receiver: 'rui@armada.digital',
|
||||||
|
|
||||||
senderUsername: 'Rui',
|
senderUsername: 'Rui',
|
||||||
meetingTitle: 'Simple Title meeting',
|
meetingTitle: 'Simple Title meeting',
|
@ -7,7 +7,7 @@ const {
|
|||||||
meetingID,
|
meetingID,
|
||||||
signature,
|
signature,
|
||||||
appURL,
|
appURL,
|
||||||
} = require('../emailConfigs');
|
} = require('../tempConfig');
|
||||||
|
|
||||||
let meetingInvite = {
|
let meetingInvite = {
|
||||||
from: sender,
|
from: sender,
|
||||||
|
41
services/email/transporter.js
Normal file
41
services/email/transporter.js
Normal 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);
|
Loading…
Reference in New Issue
Block a user