繁体   English   中英

NodeJS 使用 pdf 创建者通过 Email 发送 PDF

[英]NodeJS send a PDF by Email using pdf creator

我是 NodeJS 的新手。 我正在尝试从 HTML 生成一个 PDF 并使用 nodemailer 通过 email 发送它。

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: 'support@myemail.com', 
            to: 'me@myemail.com', 
            subject: "TEST", 
            html: emailBody, 
            attachments: {
                filename: 'test.pdf',
                contentType: 'application/pdf',   
                path: // How can I do it?
            }
        }); 
    });
};

Email() class 只是我对 nodemailer 的设置,它从transporter = nodemailer.createTransport(...)

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

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: 'support@myemail.com', 
            to: 'me@myemail.com', 
            subject: "TEST", 
            html: emailBody, 
            attachments: {
                filename: 'test.pdf',
                content: buffer',   
            }
        }); 
    });
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM