-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailer.js
More file actions
29 lines (23 loc) · 829 Bytes
/
emailer.js
File metadata and controls
29 lines (23 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
const nodemailer = require('nodemailer');
const {logger} = require('./utilities/logger');
// stored in `.env` -- never store passwords, api keys
// etc. inside source code
const {SMTP_URL} = process.env;
// `emailData` is an object that looks like this:
// {
// from: "foo@bar.com",
// to: "bizz@bang.com, marco@polo.com",
// subject: "Hello world",
// text: "Plain text content",
// html: "<p>HTML version</p>"
// }
const sendEmail = (emailData, smtpUrl=SMTP_URL) => {
const transporter = nodemailer.createTransport(SMTP_URL);
logger.info(`Attempting to send email from ${emailData.from}`);
return transporter
.sendMail(emailData)
.then(info => console.log(`Message sent: ${info.response}`))
.catch(err => console.log(`Problem sending email: ${err}`));
}
module.exports = {sendEmail};