将 PDF 作为电子邮件附件发送时出错 - 无法启动浏览器进程

发布于 2025-01-12 09:14:26 字数 1867 浏览 0 评论 0原文

我们在发送邮件附件时遇到问题。我们的场景是这样的,我们有一个按钮“发送到我的电子邮件”,它收集登录用户的电子邮件并将填写的表格作为 pdf 发送到电子邮件附件。在我们的本地计算机上一切正常,但我们在实时测试站点上遇到错误。

我们的后端expressjs控制器代码:

const sendFormToEmail = async (req, res, next) => {
  try {
    const { formDetails } = req.body;

    const to = formDetails?.email;
    const from = "Our App Name here";
    const subject = `Form Attachment`;
    const html = emailTemplate({ formDetails });

    let options = { format: "A4" };
    let file = { content: html };
    const pdfBuffer = await html_to_pdf.generatePdf(file, options);

    await sendEmail({
      to,
      subject,
      from,
      html,
      pdfBuffer,
      filename: "form.pdf",
    });

    res.status(200).send({
      status: true,
      message: "Form sent to email successfully",
    });
  } catch (err) {
    console.log("Error is ", err);
    res.status(500).send({
      status: false,
      message: "Failed to send Form on an email",
    });
  }
};

sendEmail函数代码:

async function sendEmail({
  to,
  from,
  subject,
  text,
  html,
  pdfBuffer,
  filename,
}) {
  try {
    const sendEmailResponse = await SENDGRID.send({
      from,
      to,
      text,
      html,
      subject,
      attachments: [
        {
          content: pdfBuffer.toString("base64"),
          filename: filename,
          type: "application/pdf",
          disposition: "attachment",
        },
      ],
    });
    console.log("EMAIL_SUCCESSFULLY_SEND: ", sendEmailResponse);
    return true;
  } catch (err) {
    console.log(err.response.body.errors);
    throw err;
  }
}

我们面临的错误:

错误就是错误:无法启动浏览器进程! /root/application-name/node_modules/html-pdf-node/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome:加载共享库时出错:libatk-1.0.so.0:无法打开共享对象文件:没有这样的文件或目录

请帮助我们解决这个问题

We're facing an issue while sending an attachment to a mail. Our scenario is something like, we're having a button "Send to My Email" which collects the logged-in user email and sends the filled form as a pdf to an email attachment. Everything is working fine on our local machine, but we're getting an error on the live testing site.

Our backend expressjs controller code:

const sendFormToEmail = async (req, res, next) => {
  try {
    const { formDetails } = req.body;

    const to = formDetails?.email;
    const from = "Our App Name here";
    const subject = `Form Attachment`;
    const html = emailTemplate({ formDetails });

    let options = { format: "A4" };
    let file = { content: html };
    const pdfBuffer = await html_to_pdf.generatePdf(file, options);

    await sendEmail({
      to,
      subject,
      from,
      html,
      pdfBuffer,
      filename: "form.pdf",
    });

    res.status(200).send({
      status: true,
      message: "Form sent to email successfully",
    });
  } catch (err) {
    console.log("Error is ", err);
    res.status(500).send({
      status: false,
      message: "Failed to send Form on an email",
    });
  }
};

sendEmail function code:

async function sendEmail({
  to,
  from,
  subject,
  text,
  html,
  pdfBuffer,
  filename,
}) {
  try {
    const sendEmailResponse = await SENDGRID.send({
      from,
      to,
      text,
      html,
      subject,
      attachments: [
        {
          content: pdfBuffer.toString("base64"),
          filename: filename,
          type: "application/pdf",
          disposition: "attachment",
        },
      ],
    });
    console.log("EMAIL_SUCCESSFULLY_SEND: ", sendEmailResponse);
    return true;
  } catch (err) {
    console.log(err.response.body.errors);
    throw err;
  }
}

The error we're facing:

Error is Error: Failed to launch the browser process!
/root/application-name/node_modules/html-pdf-node/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory

Please, help us in getting rid of this issue

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深爱成瘾 2025-01-19 09:14:26

所以,基本上,我找到了这个 这里

So, basically, I found the solution for this here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文