how to send attachments to node mailer file not found

Solutions on MaxInterview for how to send attachments to node mailer file not found by the best coders in the world

showing results for - "how to send attachments to node mailer file not found"
Ewenn
18 May 2019
1function sendEmail(userEmail, htmlString, requestSnap, FIREBASE_WEB) {
2
3fileName = "test.pdf";
4folderName = "./" + uuid.v4();
5mkdirp(folderName, function (err) {
6    if (err) console.error(err)
7    else console.log(folderName + ' folder created!')
8});
9
10pdf.create(htmlString + userEmail, options).toFile(folderName + '/' + fileName, function (err, res) { // if the file doesnt exist it will be created
11    if (err) return console.log(err);
12    console.log(res);
13
14    var transporter = nodemailer.createTransport(smtpTransport({
15        service: 'Gmail',
16        auth: {
17            user: '...',
18            pass: '...'
19        }
20    }));
21    console.log("\nPATH " + folderName + "/" + fileName);
22
23    var mailOptions = {
24        from: 'marija.lukaroska.cw@gmail.com',
25        to: userEmail,
26        subject: 'So mail vo pdf-ot',
27        text: 'Hellow',
28        attachments: [{
29            path: folderName + "/" + fileName
30        }]
31    };
32
33    transporter.sendMail(mailOptions, function (error, info) {
34        if (error) {
35            console.log("ERROR kkkk " + error);
36        } else {
37            console.log('Email sent: ' + info.response);
38            console.log("REQUEST SNAP " + JSON.stringify(requestSnap));
39        }
40
41        deleteFolderRecursive(folderName);
42    });
43});
44}
similar questions