-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_4_send_email_report.js
62 lines (50 loc) · 1.97 KB
/
example_4_send_email_report.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
51
52
53
54
55
56
57
58
59
60
61
62
/* Send FusionExport files as attachments via mail
* Sending email using package - nodemailer (https://nodemailer.com)
* Provide your SMTP details for settiing up (line no. 28).
* If this is something new for you, try using https://mailtrap.io for quickly getting started.
* If you are using Gmail, read the setup instructions here - https://nodemailer.com/usage/using-gmail
* Finally, provide email metadata (details like subject, to, from) while sending email (line no. 43).
*/
const nodemailer = require('nodemailer');
const path = require('path');
// Require FusionExport
const { ExportManager, ExportConfig } = require('..');
// Instantiate ExportManager
const exportManager = new ExportManager();
// Instantiate ExportConfig and add the required configurations
const exportConfig = new ExportConfig();
// nodemailer configuration
const transporter = nodemailer.createTransport({
host: '<HOST>',
auth: {
user: "<USERNAME>",
pass: "<PASSWORD>",
},
});
exportConfig.set('chartConfig', path.join(__dirname, 'resources', 'multiple.json'));
exportConfig.set('templateFilePath', path.join(__dirname, 'resources', 'template.html'));
exportConfig.set('type', 'pdf');
exportManager
.export(exportConfig, '.', true)
.then((exportedFiles) => {
transporter.sendMail({
from: "<SENDER'S EMAIL>",
to: "<RECEIVERS'S EMAIL>",
subject: 'FusionExport',
text: 'Hello,\n\nKindly find the attachment of FusionExport exported files.\n\nThank you!',
attachments: exportedFiles.map((exportedFile, index) => ({
filename: `export${index === 0 ? '' : `-${index}`}.pdf`,
path: exportedFile,
contentType: 'application/pdf',
})),
}, (error) => {
if (error) {
console.log('FusionExport Node Client: error sending mail - ', error);
} else {
console.log('FusionExport Node Client: email sent');
}
});
})
.catch((err) => {
console.log('FusionExport Node Client: error exporting charts - ', err);
});