【问题标题】:nodemailer not sending attachmentnodemailer不发送附件
【发布时间】:2016-04-23 19:25:25
【问题描述】:

我正在使用 nodemailer 发送邮件和附件。但在发送附件之前,我需要验证它是否存在,因此我将它分配给一个变量。但是当我使用变量时,它不会发送附件

工作

smtpTransport.sendMail({
            from: data_to_send.from,
            to: data_to_send.to,
            subject: data_to_send.subject,
            atachments: data_to_send.attachments,
            text: data_to_send.text,
            html: data_to_send.html,
            attachments: [{
                filename: 'file1' + file1ext,
                filePath: file1Path 
            }, {
                filename: 'file2' + file2ext, 
                filePath: file2Path 

            }],
        }
.....

不工作

 data_to_send.attachments = [{
    filename: 'file1' + file1ext, //"file1.jpg",
    filePath: file1Path //'uploads/file1.jpg'
}, {
    filename: 'file2' + file2ext, //"file2.jpg",
    filePath: file2Path //'uploads/file2.jpg'
}];

console.log(data_to_send.attachments)
smtpTransport.sendMail({
        from: data_to_send.from,
        to: data_to_send.to,
        subject: data_to_send.subject,
        atachments: data_to_send.attachments,
        text: data_to_send.text,
        html: data_to_send.html,
        attachments: data_to_send.attachments
    },
....

【问题讨论】:

  • 那么,你说什么?

标签: javascript node.js nodemailer


【解决方案1】:

两个错误:

  1. 据说你有两条线做同样的事情。删除这一行(有错字,重复):

    atachments: data_to_send.attachments,
    
  2. filePath 更改为 pathcheck the docsthis issue

    data_to_send.attachments = [{
      filename: 'file1' + file1ext,
      path: file1Path
    }, {
      filename: 'file2' + file2ext,
      path: file2Path
    }];
    

【讨论】:

    猜你喜欢
    • 2016-03-30
    • 2022-07-15
    • 2020-08-05
    • 2019-09-30
    • 2022-01-16
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 2019-10-06
    相关资源
    最近更新 更多