0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

nodemailerでWindowsパスを使って添付ファイルを指定する。

Posted at

CSVでメールの情報を受け取ってnodemailerで送信するスクリプトを書いていた。
CSVには添付ファイルの情報がwindows形式パスで入ってくる。

C:\hoge\hoge.jpg

↓以下のコードで送信できると思って一生懸命実行しまくっていた

let message = {
  from: config.FromAddress,
  to: targetMail.to,
  subject: targetMail.subject,
  text: targetMail.body,
  attachments: [
    {
      filename: 'hoge.jpg',
      path: 'C:\\hoge.jpg'
    },
  ]
};

送れない。。。
結果、これで送ることが出来た

let message = {
  from: config.FromAddress,
  to: targetMail.to,
  subject: targetMail.subject,
  text: targetMail.body,
  attachments: [
    {
      filename: 'hoge.jpg',
      content: fs.createReadStream('C:\\hoge.jpg')
    },
  ]
};

パスではなくストリームを渡す

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?