mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 08:47:43 +00:00
feat: add support for specifying smtp server (#458)
Co-authored-by: Adrian Martin <adrian.martin@nbcuni.com>
This commit is contained in:
+3
-1
@@ -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)
|
||||
};
|
||||
|
||||
|
||||
@@ -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
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user