计算在 Nodejs 中发送的电子邮件数量

编程入门 行业动态 更新时间:2024-10-05 01:13:42

计算在 Nodejs 中发送的<a href=https://www.elefans.com/category/jswz/34/1770696.html style=电子邮件数量"/>

计算在 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 中发送的电子邮件数量

本文发布于:2024-05-30 10:41:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   数量   Nodejs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!