Help Needed: Error with PDF Generation when Sending Email

Hello, community!

I’m encountering an issue while trying to send an email through a Gmail account. The process fails with the error shown below. It seems related to generating a PDF, possibly due to broken image links or network restrictions. Has anyone faced a similar problem or know how to resolve this?

frappe@180992f368c6:~/frappe-bench$ bench version
ecommerce_integrations 1.17.0
erpnext 15.38.1
frappe 15.44.1
hrms 15.31.0
payments 0.0.1
print_designer 1.4.3
webshop 0.0.1
wkhtmltopdf --version
wkhtmltopdf 0.12.6.1 (with patched qt)

Error Details:

Traceback (most recent call last):
  File "apps/frappe/frappe/utils/pdf.py", line 90, in get_pdf
    filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "env/lib/python3.11/site-packages/pdfkit/api.py", line 75, in from_string
    return r.to_pdf(output_path)
           ^^^^^^^^^^^^^^^^^^^^^
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
  File "env/lib/python3.11/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
Exit with code 1 due to network error: ContentOperationNotPermittedError


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 167, in send
    message = ctx.build_message(recipient.recipient)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 315, in build_message
    message = self.include_attachments(message)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 392, in include_attachments
    print_format_file = frappe.attach_print(**attachment)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 2232, in attach_print
    else get_print(doctype, name, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/__init__.py", line 2191, in get_print
    return get_pdf(html, options=pdf_options, output=output) if as_pdf else html
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "apps/frappe/frappe/utils/pdf.py", line 98, in get_pdf
    frappe.throw(_("PDF generation failed because of broken image links"))
  File "apps/frappe/frappe/__init__.py", line 652, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 617, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 568, in _raise_exception
    raise exc
frappe.exceptions.ValidationError: PDF generation failed because of broken image links

During handling of this error, a ValidationError is raised:

frappe.exceptions.ValidationError: PDF generation failed because of broken image links

It looks like the PDF generation might be failing due to inaccessible image URLs. If anyone has suggestions or a solution for this issue, I’d greatly appreciate your help!

Thank you in advance!

Check this

I’m still facing the issue, even after adding host_name to both site_config.json and common_site_config.json during the site creation in the docker-compose setup.

echo "sites/common_site_config.json found";
       bench new-site --no-mariadb-socket --admin-password="${ADMIN_PWD}" --db-root-password="${DB_ROOT_PWD}" --install-app erpnext --set-default "${SITE_NAME}";
       bench set-config -g host_name "https://${SITE_NAME}";
       bench --site "${SITE_NAME}" set-config host_name "https://${SITE_NAME}";

image
image

And the libssl-dev is installed:
image

I had the same problem. I was tweaking many configurations with- and without the https:// in the site_config and also setting my /etc/hosts for my own domain to 127.0.0.1…

I can not remember what worked in the end, but play around with these, I hope this help, but I am not sure…