2017-08-24 41 views
0

我試圖使用Nodemailer發送帶附件的電子郵件。不管我做什麼,如果我指定一個attachments屬性,電子郵件就會變空(無附件,無html,無文本)。按預期發送沒有任何附件的電子郵件。這裏是我到目前爲止的代碼:帶附件的郵件在使用Nodemailer時出現空白

transporter.sendMail({ 
    to: `${toTitleCase(i.nome)} <${i.email}>`, 
    subject: 'Treinamentos', 
    text: 'hello!', 
    html: `Embedded image: <img src="cid:[email protected]"/>`, 
     attachments: [ 
      { 
       filename: 'newimg.jpg', 
       path: __dirname + '/src/img/newimg.jpg', 
       cid: '[email protected]' 
      } 
     ] 
    }, (err, info)=> { 
     console.log(err); 
     console.log(info); 
    }); 

我一直在使用的content代替path也試過,相同的結果。我還應該注意,err回調是空的。

+0

您至少缺少一件東西:'contentDisposition:'inline'' in your file(s)。看一下我的代碼,我還添加了一個鍵:'編碼:'base64''(不知道這是否是必需的) – yBrodsky

+0

回覆此回答https://stackoverflow.com/a/45388543/7635845 –

+0

@SyedAyeshaBebe不確定這與我的問題有關,因爲我甚至沒有使用Gmail。無論哪種方式,我找出了什麼是錯的,並提交它作爲答案。 –

回答

0

我想通了。我已將'Content-type': 'text/html; charset=UTF-8'設置爲transporter對象上的標題。刪除該行解決了問題。

相關問題