I am using Netlify to host my github repo and I am trying to send an attachment via email using nodemailer in my submission-created.js:
let replyMailOptions = {
from: GMAIL,
to: mail,
subject: `My Test Subject`,
html: `<p>a message</p>`,
attachments: {
path: './test.txt'
}
};
but it isn’t locating the file. I’ve tried placing the file under /functions/test.txt, under a subfolder /functions/test/test.txt as well as /assets/test.txt. I’ve tried to view the files under the current folder with
I keep going down rabbit holes and not sure which path leads me to what I want. Some of these examples being: build configurations (something about my relative/absolute paths?), Netlify’s “backend” options, large media, site generators and I’m getting overwhelmed and feel like I might be overcomplicating a simple solution.
Actually, scratch that…
Looks like it worked on my local dev environment, but not working on prod.
I am getting error message [Error: ENOENT: no such file or directory, open '/var/task/src/functions/test.pdf']
Before this I am assigning and logging this and it seems to work on prod:
let contents = path.resolve(__dirname + “/test.pdf”);
console.log(path.resolve(contents));
Found the solution. Looks like functions within subdirectories are bundled with others within. I tried this initially but wouldn’t build the sub-directory functions, so I thought this wasn’t the solution. The solution was to name the subfolder the same as the function name. functions/myfunc/myfunc.js