Wkhtmltopdf error stopping emails with doctype attachments

I have an issue with emails failing whenever a doctype is attached.

The symptoms are

  1. When an email with attchments is queued it is not sent and produces an error (see log file below) after 3 send attempts
  2. When the email with attachments is manually sent from the mail queue (using Send Now) the email is immediately sent and the attachments are correctly received (as pdf which verifies that the wkhtmlpdf routine works correctly)
  3. When an email without attachments is queued it is sent without issue

The following error log is produced

File “/cloudclusters/erpnext/frappe-bench/apps/frappe/frappe/email/doctype/email_queue/email_queue.py”, line 135, in send

  • message = ctx.build_message(recipient.recipient)*
  • File “/cloudclusters/erpnext/frappe-bench/apps/frappe/frappe/email/doctype/email_queue/email_queue.py”, line 294, in build_message*
  • message = self.include_attachments(message)*
  • File “/cloudclusters/erpnext/frappe-bench/apps/frappe/frappe/email/doctype/email_queue/email_queue.py”, line 353, in include_attachments*
  • print_format_file = frappe.attach_print(*attachment)
  • File “/cloudclusters/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 2087, in attach_print*
  • content = get_print(doctype, name, *kwargs)
  • File “/cloudclusters/erpnext/frappe-bench/apps/frappe/frappe/init.py”, line 2040, in get_print*
  • return get_pdf(html, options=pdf_options, output=output)*
  • File “/cloudclusters/erpnext/frappe-bench/apps/frappe/frappe/utils/pdf.py”, line 38, in get_pdf*
  • filedata = pdfkit.from_string(html, options=options or {}, verbose=True)*
  • File “/cloudclusters/erpnext/frappe-bench/env/lib/python3.10/site-packages/pdfkit/api.py”, line 75, in from_string*
  • return r.to_pdf(output_path)*
  • File “/cloudclusters/erpnext/frappe-bench/env/lib/python3.10/site-packages/pdfkit/pdfkit.py”, line 201, in to_pdf*
  • self.handle_error(exit_code, stderr)*
  • File “/cloudclusters/erpnext/frappe-bench/env/lib/python3.10/site-packages/pdfkit/pdfkit.py”, line 155, in handle_error*
  • raise IOError(‘wkhtmltopdf reported an error:\n’ + stderr)*

It appears that the error is related to routine wkhtmltopdf

The server OS is Ubuntu 20.04.2 LTS
wkhtmlpdf version is 0.12.6 (with patched qt)

Can anybody

  1. Identify why emails with attachments are failing to send?
  2. Confirm the compatibility of the versions?
  3. Identify the issue and the possible solution?

All support appreciated.

Hi Alan - this is a low confidence guess but you might check the write permissions on whatever folder it is trying to write the pdf file to, as per output_path parameter to the r.to_pdf call. Not sure where that would be, some temporary file folder on the server.