-
Notifications
You must be signed in to change notification settings - Fork 3
/
mailer.js
49 lines (40 loc) · 1.55 KB
/
mailer.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict";
const nodemailer = require("nodemailer");
const {
users
} = require('./server')
// async..await is not allowed in global scope, must use a wrapper
async function main() {
console.log('inside mailer')
console.log(users)
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
let testAccount = await nodemailer.createTestAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass // generated ethereal password
}
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: `[email protected]`, // sender address
to: `${users[0].email}`, // list of receivers
subject: ` SUGGESTION `, // Subject line
text: ` ${users[0].message} `, // plain text body
html: `<b> ${users[0].message} </b>` // html body
});
console.log("Message sent: %s", info.messageId);
// Message sent: <[email protected]>
// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
}
// main().catch(console.error);
module.exports = {
main
}