【问题标题】:Nodemailer Message Configuration Missing 'From'Nodemailer 消息配置缺少“发件人”
【发布时间】:2020-04-18 02:33:13
【问题描述】:

所以我的 nodemailer 传输工作正常(大部分情况下)但是,我现在正在尝试嵌入图像。现在的问题是我的 mailOptions 对象中有附加的“附件”选项,它会引发以下错误。

Error: 'from' parameter is missing

这很奇怪,因为我肯定有一个 from 参数。没有附件的电子邮件可以正常发送。不知道我做错了什么。

var mailOptions = {                             
    from: 'confirmation@donotreply.com',
    to: email,
    subject: 'Account verification',
    html:'<p>Hello,\n\n' + 'Please verify your account by clicking the link' + confirmationLink + '\n\n' + '<img src="uniqueqr@qr.example" alt="something went wrong"/>',
    attachments: [{
        filename: 'qr.png',
        path: '../path/to/my/file/qr.png',
        cid: 'uniqueqr@qr.example'
    }],
};

【问题讨论】:

  • 确保关闭 html 中的 &lt;p&gt; 标记,并在关闭方括号后去掉最后一个逗号
  • 欣赏它,但运气不好,我已经尝试了所有逗号组合,没有逗号等,关闭 并没有什么不同,但总体而言是一个很好的收获。谢谢。

标签: node.js nodemailer


【解决方案1】:

尝试以下方法:

const mailOptions = Object.freeze({
        from: 'confirmation@donotreply.com',
        to: email,
        subject: 'Account verification',
        html: '<p>Hello</p>,\n\n' + 'Please verify your account by clicking the link' + confirmationLink + '\n\n' + '<img src="cid:uniqueqr@qr.example" alt="something went wrong"/>',
        attachments: [{
           filename: 'image.png',
           path: '/path/to/file',
           cid: 'uniqueqr@qr.example'
       }]
    });

注意img标签内的cid

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-18
    相关资源
    最近更新 更多