forked from ERTHIRTEEN/metabase-pulses
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mailService.js
50 lines (42 loc) · 1.27 KB
/
mailService.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
50
const nodemailer = require("nodemailer");
const config = require('config');
function getHtml(questions) {
let html = ""
for ( question of questions ) {
html += `<a href="${question.url}"><h3>${question.name}</h3></a>
<img src="cid:${question.id}"/>
<br/><br/>`
}
return html
}
function getAttachments(questions) {
attachments = [];
for ( question of questions ) {
attachments.push({
filename: `${question.imagePath}`,
path: `./${question.imagePath}`,
cid: `${question.id}`
})
}
return attachments;
}
async function mailQuestion(subject,mailTo,questions) {
let transporter = nodemailer.createTransport({
host: config.get('smtp.host'),
port: 587,
secure: false,
auth: {
user: config.get('smtp.user'),
pass: config.get('smtp.password')
}
});
let info = await transporter.sendMail({
from: 'metabase <[email protected]>',
to: mailTo,
subject: subject,
text: "Pulses report",
html: getHtml(questions),
attachments: getAttachments(questions)});
console.log("Message sent: %s", info.messageId);
}
module.exports = mailQuestion