NodeJS使用pdf创建者通过电子邮件发送PDF

问题描述 投票:0回答:1

我是NodeJS的新手。我正在尝试从HTML生成PDF并使用nodemailer通过电子邮件发送。

exports.testReqID = async (req, res, next) => {
    const ID = req.params.myID;

    const htmlData = `
        <html>
            <head></head>
            <body>
                <h1>PDF Test. ID: ${ID}</h1>
            </body>
        </html>
    `; // Just a test HTML

    pdf.create(htmlData).toBuffer(function(err, buffer){
        let emailBody = "Test PDF";
        const email = new Email();
        const transporter = email.getTransporter();
        await transporter.sendMail({
            from: '[email protected]', 
            to: '[email protected]', 
            subject: "TEST", 
            html: emailBody, 
            attachments: {
                filename: 'test.pdf',
                contentType: 'application/pdf',   
                path: // How can I do it?
            }
        }); 
    });
};

Email()类只是我对nodemailer的设置,它从transporter = nodemailer.createTransport(...)返回一个传输器>

我是NodeJS的新手。我正在尝试从HTML生成PDF并使用nodemailer通过电子邮件发送。 Exports.testReqID =异步(req,res,next)=> {const ID = req.params.myID; const ...

node.js nodemailer html-pdf
1个回答
1
投票

您可以将其作为缓冲区发送。 docs

© www.soinside.com 2019 - 2024. All rights reserved.