3

I just wanted to know how to specify the path in attachments in Nodemailer. I am getting this above-mentioned error. Can anyone specify how to specify the path?

var imagePath = path.join(__dirname, '/images/')

attachments : [{ filename: "Header@3x.png", path:${imagePath}, cid: 'headerImage' }]

Sree Nath
  • 543
  • 6
  • 19
  • Check [**this**](https://stackoverflow.com/a/42677294/5452965) out. Are you sure that `imagePath` variable contains the correct path to the image ? – codtex Jul 12 '18 at 11:51
  • Yeah, I consoled it. It is the exact path where images are stored. – Sree Nath Jul 12 '18 at 11:52
  • 1
    Yes but you need to provide the full path to the image, not only the directory. I mean `path/to/image/directory` is wrong and `path/to/image/directory/image.extension` is correct – codtex Jul 12 '18 at 11:54
  • But I am already specifying the filename. ok, let me try this way. – Sree Nath Jul 12 '18 at 11:54
  • Thanks @codtex It worked. Thanks for helping me out. – Sree Nath Jul 12 '18 at 11:59
  • You are welcome friend – codtex Jul 12 '18 at 12:02
  • 1
    Possible duplicate of [NPM stuck giving the same error EISDIR: Illegal operation on a directory, read at error (native)](https://stackoverflow.com/questions/34959038/npm-stuck-giving-the-same-error-eisdir-illegal-operation-on-a-directory-read-a) – codtex Jul 12 '18 at 12:03

1 Answers1

9

I had the same problem. But I resolved by giving the full path till Image.

For example:

var imagePath = path.join(__dirname, '/images/Header@3x.png'); // In this line, Give the full path of image.
attachments : [{
              filename: "Header@3x.png",
              path:${imagePath},         // __dirname+'/images/Header@3x.png'
              cid: 'headerImage'
}]

And your HTML will be :

<div>
   <img src="cid:headerImage" alt="Header Image" width="100" height="100"/>
</div>

( In the path IMAGE_NAME is important and required.)

Shubham Verma
  • 8,783
  • 6
  • 58
  • 79