将 PDF 作为电子邮件附件发送时出错 - 无法启动浏览器进程
我们在发送邮件附件时遇到问题。我们的场景是这样的,我们有一个按钮“发送到我的电子邮件”,它收集登录用户的电子邮件并将填写的表格作为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,基本上,我找到了这个 这里。
So, basically, I found the solution for this here.