2017-08-24 53 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对象上的标题。删除该行解决了问题。