-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (34 loc) · 959 Bytes
/
script.js
File metadata and controls
39 lines (34 loc) · 959 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
30
31
32
33
34
35
36
37
38
39
import { config } from "dotenv";
import nodemailer from "nodemailer";
import path from "path";
config();
// Email configurations, create transporter
const transporter = nodemailer.createTransport(
{
host: process.env.HOST,
port: 2525,
auth: {
user: process.env.USERNAME, // host user name - mailtrap
pass: process.env.PASSWORD // host password - mailtrap
}
}
);
// chosse the file to sent
const filename = 'daily-report.pdf'
const maileOptions = {
from: process.env.MAILID,
to: process.env.RECIVER,
subject: 'Daily Report',
text: 'Please find the attached daily report',
attachments: [
{
filename: filename,
path: path.join('./attachments', filename)
}
]
}
// sent email to
transporter.sendMail(maileOptions, (error, info) => {
if (error) throw new Error(error);
else console.log('Email sent: ', info.response);
});