0

using these versions

"next": "12.0.7"
"nodemailer": "^6.7.2"

I am building a mailing service using NextJS, but i encountered some problems:

  • gmail not rendering the images (solved by sending as attachment the images i want to render)
  • In production, the mailing service can't find the images inside the public folder
  • Mails sent in dev environment work perfect, but in production the images don't render

I have the following structure

pages
   -api
       -contact.js
public
   -images
       -image_name.png

in contact.js

as suggested here

...

 mailData = {
                from: process.env.THE_EMAIL,
                to: req.body.email,
                subject: `SOME_SUBJECT`,
                attachments: [
                    {
                        filename: 'image_name.png',
                        path: 'public/images/image_name.png',
                        cid: 'SOME_ID_FOR_NODEMAILER',
                    }
             ]}

...

When Im working in localhost, the mailing service works perfect and the images are found, but when is in production (deployed with Vercel) it cannot find the images.

Any thoughts or alternatives? Should i host the images in a CDN and forget about it?

juliomalves
  • 21,997
  • 12
  • 75
  • 81
Pato
  • 39
  • 4
  • Can -you- not find them or can your software not find them? – Mason Stedman Jan 01 '22 at 19:21
  • the software cant find them, i get an error that the system cant find the file – Pato Jan 02 '22 at 12:42
  • Have you checked the owner \ permissions? – Mason Stedman Jan 02 '22 at 12:47
  • Does this answer your question: [Next.js: How to get static assets from within getStaticProps](https://stackoverflow.com/questions/65860421/next-js-how-to-get-static-assets-from-within-getstaticprops)? Try using `path.join(process.cwd(), 'public/images/image_name.png')` as the image's path. – juliomalves Jan 05 '22 at 17:21

0 Answers0