What is the correct way to set the attachment path in nodeMailer?

I am new to the Nodejs world. I want to send an email with an embedded image. But my image did not show through email. I thought this could be my file path setting. Here are my mailOptions,

    var mailOptions = {
        from: 'mymail@gmail.com',
        to: to,
        subject: subject,
        html: html,
        attachments: [{
            filename: "logo.png",
            filePath: "/images/logo.png",
            cid: "logo-mail"
        }]
    };

And my directory that stores my static files,

myproject/
         assets/
               images/
               js/
               styles/

And this is my html,

<img src="cid:logo-mail" />

Here is my result in the email,

<img src="cid.php?mid=e_ZGHjAQV4ZQLlAGNkZQNjZGN1AQt3Zt==&amp;pj=logo-mail" alt="cid.php?mid=e_ZGHjAQV4ZQLlAGNkZQNjZGN1AQ">

I am not sure if the file path is set correctly as follows:

filePath: "/images/logo.png"
+4
source share
2 answers

I liked it

filePath: process.cwd() + "/assets/images/logo.png"

And now it works!

Thank you all for your help.

+2
source

You need the full path to your image.

http://www.example.com/images/logo.png

gmail.com,

gmail.com/images/logo.png
+1

Source: https://habr.com/ru/post/1585036/


All Articles