Email are in sending status

Unable to send emails from the user. It stays in sending status. I have restarted the services and the scheduler is enabled. There are 3 workers that are active. Can anyone please help ?

The following is the error log

23:40:30 Traceback (most recent call last):
  File "/home/bench/erpnext/env/lib/python3.10/site-packages/rq/worker.py", line 1061, in perform_job
    rv = job.perform()
  File "/home/bench/erpnext/env/lib/python3.10/site-packages/rq/job.py", line 821, in perform
    self._result = self._execute()
  File "/home/bench/erpnext/env/lib/python3.10/site-packages/rq/job.py", line 844, in _execute
    result = self.func(*self.args, **self.kwargs)
  File "/home/bench/erpnext/apps/frappe/frappe/utils/background_jobs.py", line 166, in execute_job
    method(**kwargs)
  File "/home/bench/erpnext/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 183, in send_mail
    record.send(is_background_task=is_background_task, smtp_server_instance=smtp_server_instance)
  File "/home/bench/erpnext/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 134, in send
    message = ctx.build_message(recipient.recipient)
  File "/home/bench/erpnext/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 293, in build_message
    message = self.include_attachments(message)
  File "/home/bench/erpnext/apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 356, in include_attachments
    print_format_file = frappe.attach_print(**attachment)
  File "/home/bench/erpnext/apps/frappe/frappe/__init__.py", line 2075, in attach_print
    content = get_print(doctype, name, **kwargs)
  File "/home/bench/erpnext/apps/frappe/frappe/__init__.py", line 2028, in get_print
    return get_pdf(html, options=pdf_options, output=output)
  File "/home/bench/erpnext/apps/frappe/frappe/utils/pdf.py", line 38, in get_pdf
    filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
  File "/home/bench/erpnext/env/lib/python3.10/site-packages/pdfkit/api.py", line 75, in from_string
    return r.to_pdf(output_path)
  File "/home/bench/erpnext/env/lib/python3.10/site-packages/pdfkit/pdfkit.py", line 201, in to_pdf
    self.handle_error(exit_code, stderr)
  File "/home/bench/erpnext/env/lib/python3.10/site-packages/pdfkit/pdfkit.py", line 155, in handle_error
    raise IOError('wkhtmltopdf reported an error:\n' + stderr)
OSError: wkhtmltopdf reported an error:
The switch --print-media-type, is not support using unpatched qt, and will be ignored.The switch --header-html, is not support using unpatched qt, and will be ignored.The switch --footer-html, is not support using unpatched qt, and will be ignored.The switch --disable-smart-shrinking, is not support using unpatched qt, and will be ignored.QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-erpnext'
Exit with code 1 due to network error: ConnectionRefusedError

If you are emailing PDF files, then you may want to check if there is any error in generation of those files or it could be a problem with the version of wkhtmltopdf also. You will have to debug step by step.

So I realized that installing wkhtmltopdf solved the issue.

However I found a BUG

We are running it on a non standard port and the welcome email has links which does not capture this port in the welcome email. Can you tell us which python file we need to patch so that we can do it manually ?

1 Like