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
+2
View File
@@ -38,6 +38,8 @@ SHOW_ONLY_MODELS=""
SHOW_ONLY_SERIES=""
SLACK_CHANNEL=""
SLACK_TOKEN=""
SMTP_ADDRESS=""
SMTP_PORT=""
STORES=""
TELEGRAM_ACCESS_TOKEN=""
TELEGRAM_CHAT_ID=""
+2
View File
@@ -105,6 +105,8 @@ Here is a list of variables that you can use to customize your newly copied `.en
| `SHOW_ONLY_SERIES` | Filter to show specified series | Comma separated, e.g.: `3080` |
| `SLACK_CHANNEL` | Slack channel for posting | E.g.: `update`, no need for `#` |
| `SLACK_TOKEN` | Slack API token | |
| `SMTP_ADDRESS` | IP Address or fqdn of smtp server |
| `SMTP_PORT` | TCP Port number on which the smtp server is listening for connections | Default: `25` |
| `STORES` | [Supported stores](#supported-stores) you want to be scraped | Comma separated, default: `nvidia` |
| `SCREENSHOT` | Capture screenshot of page if a card is found | Default: `true` |
| `TELEGRAM_ACCESS_TOKEN` | Telegram access token | |
+3 -1
View File
@@ -67,6 +67,8 @@ const notifications = {
},
email: {
password: envOrString(process.env.EMAIL_PASSWORD),
smtpAddress: envOrString(process.env.SMTP_ADDRESS),
smtpPort: envOrNumber(process.env.SMTP_PORT, 25),
to: envOrString(process.env.EMAIL_TO, envOrString(process.env.EMAIL_USERNAME)),
username: envOrString(process.env.EMAIL_USERNAME)
},
@@ -135,7 +137,7 @@ const page = {
};
const proxy = {
address: envOrString(process.env.PROXY_ADDRESS, ''),
address: envOrString(process.env.PROXY_ADDRESS),
port: envOrNumber(process.env.PROXY_PORT, 80)
};
+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');