最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PDF通过sendgrid api通过nodemailer发送时不可读

运维笔记admin9浏览0评论

PDF通过sendgrid api通过nodemailer发送时不可读

PDF通过sendgrid api通过nodemailer发送时不可读

我正在使用sendgrid API通过nodemailer发送交易电子邮件。但是每次发送时,它都不可读。这是我下面的post请求。

router.post('/sendPendingEmail', async (req, res) => {
  var toEmail = req.body.email
  var pdfURL = req.body.pdfDataUri
  sgMail.setApiKey(process.env.SENDGRID_API_KEY)

let mailOptions = {
      from: 'DocuSiner <[email protected]>',
      to: toEmail,
      subject: 'Patent Certificate - DocuSigner',
      html: `<p>Dear, Sir/Madam,</p><br><p>This is to inform you that the patent e-form submitted on the DocuSigner portal is <strong>APPROVED</strong>. Below is the Patent Certificate, please download the same for future use: </p><p>Thank You.</p>`,
      attachments: [
        {
          filename: 'patent.pdf',
          content: new Buffer.from(pdfURL).toString('base64'),
          type: 'application/pdf',
          disposition: 'attachment'
        }
      ]
    }

  await sgMail.send(mailOptions, (err, sent) => {
    if (err) {
      res.send(err)
    }
    res.send({
      info: sent,
      msg: 'Email Sent'
    })
  })
})
回答如下:

尝试这样。

attachments : [{filename: 'patent.pdf', 
               content: data
               type: 'application/pdf',
               disposition: 'attachment'             
}],
发布评论

评论列表(0)

  1. 暂无评论