最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

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

IT培训 admin 8浏览 0评论

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'             
}],

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. 暂无评论