DEV Community

Discussion on: How to implement email functionality with Node.js, React.js, Nodemailer, and OAuth2

Collapse
 
ankurssj profile image
Ankur-ssj

hey how can we add attachments(pdf specifically ) can you guide me in that?

Collapse
 
jlong4223 profile image
Jared Long

Hey, great question and thanks for asking. Actually, I haven't done this but I really want to figure it out now! I'll look into it to expand my article and/or make a part two.

Collapse
 
jlong4223 profile image
Jared Long • Edited

@ankurssj Hey not sure if you've figured this out or not but I have figured out the backend portion. I'm sure to wire up using attachments with the frontend will require multer to handle file requests and potentially something like Cloudinary for storing & creating urls for the attachments.

For now, here is the backend with images/files saved directly within the server project.

Essentially, you need to create an array of attachment objects (here I named mine attachmentItems) and then create an attachment key within the mailOptions object and its value is the returned result of mapping the attachmentItems.

upload-nodemailer