第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據(jù)請求正文在 nodemailer 中發(fā)送多個附件

根據(jù)請求正文在 nodemailer 中發(fā)送多個附件

函數(shù)式編程 2022-01-07 19:08:20
到目前為止,這是我正在解決的代碼function sendMail(req,res){    var transporter = nodemailer.createTransport({    host:process.env.NODEMAILER_HOST,    port:process.env.NODEMAILER_PORT,    auth: {      user: process.env.NODEMAILER_ADDRESS,      pass: process.env.NODEMAILER_PASS    }  })     mailOptions = {      from: req.body.from,      to: req.body.to,      cc: req.body.cc,      bcc: req.body.bcc,      subject: req.body.subject,      text: req.body.text,      html: req.body.html,      attachments: [        {          filename: req.body.attachments[0].filename,          path: req.body.attachments[0].path,          contentType: req.body.attachments[0].contentType        },{          filename: req.body.attachments[1].filename,          path: req.body.attachments[1].path,          contentType: req.body.attachments[1].contentType        }      ]    }  transporter.sendMail(mailOptions,function(error,info){      if(error){        console.log(error);        return res.status(400).json("Failed to Send");      }else{        res.status(201).json(req.body);      }    });}這是我的請求正文{"from": "example1@gmail.com","to": "example2@gmail.com","cc": "example3@gmail.com","bcc": "test@example.com","subject": "Test Request 1","text": "Example Text 1","html": "<p>Some Paragraph</p>","attachments": [    {        "filename": "test.doc",        "path": "dirname/test.doc",        "contentType": "application/doc"    },{        "filename": "test-coverted.pdf",        "path":  "dirname/test-converted.pdf",        "contentType": "application/pdf"            }]}如何遍歷附件而不在郵件選項中一一定義?因為如果我迭代 mailOptions 那么我需要創(chuàng)建單獨的傳輸,這反過來將為不同的附件發(fā)送不同的電子郵件。
查看完整描述

1 回答

?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗 獲得超4個贊

您在響應(yīng)正文中獲得了相同的 json 對象鍵,因此您可以直接將附件數(shù)組分配給 nodemailer mailOption 對象的附件鍵。請參閱下文。


function sendMail(req,res){  

  var transporter = nodemailer.createTransport({

    host:process.env.NODEMAILER_HOST,

    port:process.env.NODEMAILER_PORT,

    auth: {

      user: process.env.NODEMAILER_ADDRESS,

      pass: process.env.NODEMAILER_PASS

    }

  })

 mailOptions = {

  from: req.body.from,

  to: req.body.to,

  cc: req.body.cc,

  bcc: req.body.bcc,

  subject: req.body.subject,

  text: req.body.text,

  html: req.body.html,

  attachments: req.body.attachments

}


查看完整回答
反對 回復(fù) 2022-01-07
  • 1 回答
  • 0 關(guān)注
  • 222 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號