使用 node.js 发送附件数组
Sending an array of attachments with node.js
我需要使用 nodemailer 发送一封带有多个附件的电子邮件,但这些附件的数量必须由数组的大小来定义。我知道 nodemailer 可以发送多个附件,但我不知道如何发送可变数量的附件。
这是我的代码:
const files = get(req, "body.data.files");
files.forEach(file => {
senderMail.send(file, {
name: get(req, "body.data.files.name"),
url: get(req, "body.data.files.url")
});
});
let mailOptions = {
from: "Me", //
sender address
to: data.personal.user_email, // list of receivers
subject:
"An email with attachments"
text: "someText",
html: "",
attachments: [
{
filename: name,
path: url
}
]
};
部分数据来自 JSON。
准备一个Nodemailer格式的数组,然后附加到邮件对象上。
const files = get(req, "body.data.files");
const attachments = files.map((file)=>{
return { filename: file.name, path: file.url };
});
let mailOptions = {
from: "Me", //
sender address
to: data.personal.user_email, // list of receivers
subject:
"An email with attachments"
text: "someText",
html: "",
attachments: attachments
};
我需要使用 nodemailer 发送一封带有多个附件的电子邮件,但这些附件的数量必须由数组的大小来定义。我知道 nodemailer 可以发送多个附件,但我不知道如何发送可变数量的附件。
这是我的代码:
const files = get(req, "body.data.files");
files.forEach(file => {
senderMail.send(file, {
name: get(req, "body.data.files.name"),
url: get(req, "body.data.files.url")
});
});
let mailOptions = {
from: "Me", //
sender address
to: data.personal.user_email, // list of receivers
subject:
"An email with attachments"
text: "someText",
html: "",
attachments: [
{
filename: name,
path: url
}
]
};
部分数据来自 JSON。
准备一个Nodemailer格式的数组,然后附加到邮件对象上。
const files = get(req, "body.data.files");
const attachments = files.map((file)=>{
return { filename: file.name, path: file.url };
});
let mailOptions = {
from: "Me", //
sender address
to: data.personal.user_email, // list of receivers
subject:
"An email with attachments"
text: "someText",
html: "",
attachments: attachments
};