Issue with Sending Emails with PDF Attachments

I’m encountering an issue when trying to send emails with PDF attachments. The email isn’t being sent, and I receive the following error code …

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 2182, in attach_print
else get_print(doctype, name, **kwargs)
File “apps/frappe/frappe/init.py”, line 2141, 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 90, in get_pdf
filedata = pdfkit.from_string(html, options=options or {}, verbose=True)
File “env/lib/python3.10/site-packages/pdfkit/api.py”, line 75, in from_string
return r.to_pdf(output_path)
File “env/lib/python3.10/site-packages/pdfkit/pdfkit.py”, line 201, in to_pdf
self.handle_error(exit_code, stderr)
File “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:
Exit with code 1 due to network error: HostNotFoundError

It’s the PDF creation that is having a problem. Do you have any images in your print format ? If so, you’ll probably find that your hostname is not set correctly in your config, so the pdf generator cannot find a route to the image. wthtmltopdf will convert /path/to/your/image.png into http://domain/path/to/your/image.png … where domain is picked up from your config.

Sorry but it’s early morning so i can’t look at my system and tell you where the changes needs to be made. Maybe someone who is properly awake can take one with the details …

Good luck

@Kevin_Salt add "host_name": your domain . in site_config under /site/site_name .

1 Like

Without editing a file directly, I think the command is …

Bench setup add-domain --site {yoursite} {your domain name}

Please double check before you use it. I’m an experienced DevOp but new to erpnext.