2016-12-04 86 views
0

我不知道如何在電子郵件中使用嵌入圖片,利用附件。Nodemailer - 如何在模板郵件中添加附件到玉器

我在.js文件:

var mailOptions = { ... html: 'my html jade', attachments: [{ filename: 'image.png', path: '/picture/file', cid: 'myPicture' //same cid value as in the html img src }]

在玉文件:

... img(src="cid:myPicture")

當我把我的電子郵件.... 這不行。我在電子郵件中添加了附件,但郵件中沒有嵌入圖像。

+0

你有沒有嘗試設置圖像的完整路徑? –

+0

哪裏?在玉檔中? –

+0

否。在附件的'path'屬性中 –

回答

0

哇!超級老問題。你已經明白了或者現在退出編程。當我遇到同樣的問題時,谷歌帶我到了這裏。

這一切都歸結於路徑。我必須設置絕對路徑,其中包括文件名。所以,你的情況,這都會是這樣的:

var mailOptions = { 
    // ... 
    html: 'my html jade', 
    attachments: [{ 
    filename: 'image.png', 
    path: '/picture/file/image.png', 
    cid: 'myPicture' //same cid value as in the html img src 
}] 

我不能爲jade東西說話,但希望這將有助於其他一些Nodemailer。