简体   繁体   English

nodemailer不发送附件

[英]nodemailer not sending attachment

I'm using nodemailer to send a mail along with attachments.我正在使用 nodemailer 发送带有附件的邮件。 But before sending attachments i need to verify if it exists, for that reason i'm assigning it to a variable.但是在发送附件之前我需要验证它是否存在,因此我将它分配给一个变量。 But when i'm using the variable its not sending the attachment但是当我使用变量时它不发送附件

working在职的

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 

            }],
        }
.....

not working不工作

 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
    },
....

Two errors:两个错误:

  1. You have two lines supposedly doing the same thing.你有两条线应该做同样的事情。 Remove this line (there's a typo and it's duplicated):删除这一行(有一个错字,它是重复的):

     atachments: data_to_send.attachments,
  2. Change filePath to pathcheck the docs , and this issuefilePath更改为path检查 docs这个问题

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM