gpt4 book ai didi

javascript - nodemailer 不发送附件

转载 作者:行者123 更新时间:2023-11-30 00:10:14 29 4
gpt4 key购买 nike

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

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

最佳答案

两个错误:

  1. 你有两条线应该做同样的事情。删除这一行(有一个错字,它是重复的):

    atachments: data_to_send.attachments,
  2. filePath 更改为 pathcheck the docs , 和 this issue

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

关于javascript - nodemailer 不发送附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36807613/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com