-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Geoffroy Empain
committed
Dec 5, 2020
1 parent
58153d9
commit a5194f2
Showing
2 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
import nodemailer, { Transporter, TransportOptions } from 'nodemailer'; | ||
import nodemailer, { SentMessageInfo, TransportOptions } from 'nodemailer'; | ||
import { env } from '../env'; | ||
import Mail from 'nodemailer/lib/mailer'; | ||
import { Logger } from '../commons/logger/logger'; | ||
import chalk from 'chalk'; | ||
|
||
// https://nodemailer.com/smtp/#general-options | ||
export const emails: Transporter = nodemailer.createTransport(<TransportOptions>{ | ||
host: env.MELI_MAIL_HOST, | ||
port: env.MELI_MAIL_PORT, | ||
auth: env.MELI_MAIL_USERNAME && env.MELI_MAIL_PASSWORD ? { | ||
user: env.MELI_MAIL_USERNAME, | ||
pass: env.MELI_MAIL_PASSWORD, | ||
} : undefined, | ||
}); | ||
const logger = new Logger('meli.server:emails'); | ||
|
||
let transporter: { | ||
sendMail(mailOptions: Mail.Options): Promise<SentMessageInfo>; | ||
}; | ||
|
||
if (env.MELI_MAIL_HOST && env.MELI_MAIL_PORT) { | ||
logger.debug('Emails are configured'); | ||
// https://nodemailer.com/smtp/#general-options | ||
transporter = nodemailer.createTransport(<TransportOptions>{ | ||
host: env.MELI_MAIL_HOST, | ||
port: env.MELI_MAIL_PORT, | ||
auth: env.MELI_MAIL_USERNAME && env.MELI_MAIL_PASSWORD ? { | ||
user: env.MELI_MAIL_USERNAME, | ||
pass: env.MELI_MAIL_PASSWORD, | ||
} : undefined, | ||
}); | ||
} else { | ||
logger.warn(`Emails are ${chalk.red('disabled')}, will print to console`); | ||
transporter = { | ||
async sendMail(mailOptions: Mail.Options): Promise<SentMessageInfo> { | ||
logger.info('email', JSON.stringify(mailOptions, null, 2)); | ||
}, | ||
}; | ||
} | ||
|
||
export const emails = transporter; |