Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for specifying smtp server #458

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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=""
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |
Expand Down
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down Expand Up @@ -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)
};

Expand Down
25 changes: 18 additions & 7 deletions src/notification/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 2 additions & 10 deletions src/notification/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down