电子邮件数量"/>
计算在 Nodejs 中发送的电子邮件数量
我正在开发一个用户可以将文件发送到电子邮件的应用程序。我希望服务器在成功发送电子邮件后应将已发送电子邮件的数量更新到 mongodb 中的电子邮件字段。如果还有其他方法可以这样做,请帮助我。
export async function fileEmail(req, res) {
try {
var count = 0
const { email, filename } = req.body
console.log(email)
console.log(filename)
const path = `./public/files/${filename}`
const path2 = `public/files/${filename}`
const mailOptions = {
to: email,
from: process.env.EMAIL_USERNAME,
template: 'sendFile',
subject: 'File From Lizzy Business Center',
context: { email: email },
attachments: [
{
filename: filename,
path: path
}
]
}
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error)
} else {
count++
console.log(`inserting ${filename}`)
const sent = fileModel.updateOne({ title: filename }, {$set:{ emails: 2 }})
console.log(count)
if (sent) { console.log("Email sent: " + info.response) }
res.send({
status: "success",
data: "File sent successfully",
})
}
})
}
catch (error) {
console.log(error)
}
}
```This is what I have tried but it is not updating the count. I tried to console log all the data and everything seems fine but it wont update. I just even have to do the same for downloads to
回答如下:
更多推荐
计算在 Nodejs 中发送的电子邮件数量
发布评论