【问题标题】:Emails with attachments come up empty using Nodemailer使用 Nodemailer 带附件的电子邮件为空
【发布时间】:2017-08-24 21:54:45
【问题描述】:

我正在尝试使用Nodemailer 发送带有附件的电子邮件。无论我做什么,如果我指定一个attachments 属性,电子邮件就会出现空(没有附件,没有html,没有文本)。发送没有任何附件的电子邮件按预期工作。这是我到目前为止的代码:

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

我也尝试过使用content 而不是path,结果相同。我还应该注意err 回调是空的。

【问题讨论】:

  • 您至少缺少一件事:您的文件中的contentDisposition: 'inline'。查看我的代码,我还添加了一个密钥:encoding: 'base64' (不确定是否需要)
  • @SyedAyeshaBebe 不确定这与我的问题有何关系,因为我什至没有使用 Gmail。无论哪种方式,我都找出了问题所在并将其作为答案提交。
  • 我没明白你的意思!!!

标签: javascript node.js email nodemailer


【解决方案1】:

我想通了。我已将 'Content-type': 'text/html; charset=UTF-8' 设置为 transporter 对象的标题。删除该行解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-05
    • 2017-12-04
    • 1970-01-01
    • 2017-01-06
    • 2012-06-05
    • 1970-01-01
    • 2015-05-19
    相关资源
    最近更新 更多