feat: add support for specifying smtp server (#458)

Co-authored-by: Adrian Martin <adrian.martin@nbcuni.com>
This commit is contained in:
adrian549092
2020-10-06 21:46:32 -04:00
committed by GitHub
parent 332b4a8246
commit 160ae37d7b
5 changed files with 27 additions and 18 deletions
+18 -7
View File
@@ -6,16 +6,27 @@ import nodemailer from 'nodemailer';
const email = config.notifications.email;
const transporter = nodemailer.createTransport({
auth: {
pass: email.password,
user: email.username
},
service: 'gmail'
const transportOptions: any = {};
if (email.username && (email.password || email.smtpAddress)) {
transportOptions.auth = {};
transportOptions.auth.user = email.username;
transportOptions.auth.pass = email.password;
}
if (email.smtpAddress) {
transportOptions.host = email.smtpAddress;
transportOptions.port = email.smtpPort;
} else {
transportOptions.service = 'gmail';
}
export const transporter = nodemailer.createTransport({
...transportOptions
});
export function sendEmail(link: Link, store: Store) {
if (email.username && email.password) {
if (email.username && (email.password || email.smtpAddress)) {
logger.debug('↗ sending email');
const mailOptions: Mail.Options = {
+2 -10
View File
@@ -2,22 +2,14 @@ import {Link, Store} from '../store/model';
import {Print, logger} from '../logger';
import Mail from 'nodemailer/lib/mailer';
import {config} from '../config';
import nodemailer from 'nodemailer';
import {transporter} from './email';
if (config.notifications.phone.number && !config.notifications.email.username) {
logger.warn('✖ in order to recieve sms alerts, email notifications must also be configured');
logger.warn('✖ in order to receive sms alerts, email notifications must also be configured');
}
const [email, phone] = [config.notifications.email, config.notifications.phone];
const transporter = nodemailer.createTransport({
auth: {
pass: email.password,
user: email.username
},
service: 'gmail'
});
export function sendSMS(link: Link, store: Store) {
if (phone.number) {
logger.debug('↗ sending sms');