【问题标题】:How to connect html2pdf to nodemailer如何将 html2pdf 连接到 nodemailer
【发布时间】:2018-09-02 13:16:42
【问题描述】:

我有一个在线表格,申请人可以使用我安装的 html2pdf 插件下载 pdf 格式的表格。我也有 nodemailer 设置,申请人可以在其中发送电子邮件。但我不知道如何附加这两个功能。我最好将 nodemailer 表单剥离为一个提交按钮,该按钮将使用 nodemailer 将 pdf 发送到我选择的电子邮件。

【问题讨论】:

    标签: javascript html node.js nodemailer


    【解决方案1】:

    试试下面的代码它对我的工作。这个link帮你输出html2pdf

    $html2pdf->output('/absolute/path/file_xxxx.pdf', 'F');
    
    transporter.sendMail({
      from: 'foo@bar.com'.
      to: 'bar@foo.com',
      subject: 'An Attached File',
      text: 'Check out this attached pdf file',
      attachments: [{
        filename: 'file.pdf',
        path: '/absolute/path/file_xxxx.pdf',
        contentType: 'application/pdf'
      }], function (err, info) {
         if(err){
           console.error(err);
           res.send(err);
         }
         else{
           console.log(info);
           res.send(info);
         }
      });
    

    【讨论】:

    • 将生成的pdf保存在服务器上,然后将pdf附加到nodemailer的sendMail函数中。
    • 此代码假定用户在其计算机中具有 f/absolute/path/file_xxxx.pdf 的文件路径
    • 是的,如果您在服务器中实现它,则需要本地主机和服务器的绝对路径。
    • 我在脚本标签上使用了这段代码$html2pdf->output('/absolute/path/file_xxxx.pdf', 'F'); 它说的是意外令牌>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 2021-02-22
    • 2017-07-12
    • 1970-01-01
    相关资源
    最近更新 更多