gpt4 book ai didi

node.js - 使用 node.js 发送附件数组

转载 作者:太空宇宙 更新时间:2023-11-03 23:00:43 25 4
gpt4 key购买 nike

我需要使用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
};

关于node.js - 使用 node.js 发送附件数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48917508/

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