代码之家  ›  专栏  ›  技术社区  ›  Rodrigo Leite

使用NodeEmailer,带有附件的电子邮件会变空

  •  0
  • Rodrigo Leite  · 技术社区  · 7 年前

    我正在尝试使用发送带有附件的电子邮件 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 回调为空。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Rodrigo Leite    7 年前

    我想出来了。我已经准备好了 'Content-type': 'text/html; charset=UTF-8' transporter 对象删除该行修复了该问题。