diff --git a/.env-example b/.env-example index d6d94f2..f4a62b7 100644 --- a/.env-example +++ b/.env-example @@ -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="" diff --git a/README.md b/README.md index b7ea5cb..5f83886 100644 --- a/README.md +++ b/README.md @@ -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 | | diff --git a/src/config.ts b/src/config.ts index acec47a..a51346d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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) }; diff --git a/src/notification/email.ts b/src/notification/email.ts index ae14ea9..c3c94dd 100644 --- a/src/notification/email.ts +++ b/src/notification/email.ts @@ -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 = { diff --git a/src/notification/sms.ts b/src/notification/sms.ts index 01ae1c4..403ceb3 100644 --- a/src/notification/sms.ts +++ b/src/notification/sms.ts @@ -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');