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