smtplib.SMTPDataError: (501, b'Syntax error - line too long')

Using V11.1.14 - with Python 3.5 - getting this SMTP error - for outbound emails with print / pdf attachments.

(501, b’Syntax error - line too long’)
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/”, line 425, in send_one
smtpserver.sess.sendmail(email.sender, recipient.recipient, encode(message))
File “/usr/lib/python3.5/”, line 883, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (501, b’Syntax error - line too long’)

Appreciate any help / thoughts on how to resolve. Thanks.

Hi please confirm the error occurs only in the case of the pdf attachment and whether you are running a self-hosted environment thanks

Thanks for reaching out. Self hosted environment. Emails without attachment (and email with inline tables such as weekly digest, etc) are going through fine.

Problem occurs when system attempts to email a sales order notification upon submit with attach print checkbox selected (using default print format).

ok some suspect recent changes in History for frappe/email/ - frappe/frappe · GitHub

Most notably this fix communication: fix attachments in email queue and generated reports by Thunderbottom · Pull Request #6586 · frappe/frappe · GitHub

Otherwise no error it seems that any pdf generate process is part of the problem, but confirm that? The general case converts an HTML document format I believe.

You can run wkhtmltopdf from a console for eg
Steps to install wkhtmltopdf with patched Qt (version 0.12.3) (for pdf generation)

As well wkhtmltopdf must have http access to the html file, and so the FQDN domain url must be specified in /etc/hosts and sites/

Have wkhtmltopdf v0.12.3 (patched Qt) installed - was done by script.

PDF generation now works - thanks for the tips on adding the domain name to /etc/hosts and the site_config.json. Had not even realized was timing out before. Able to see / download PDF when clicking on the PDF button (under print icon for sales order document)

However when emailing same sales order with attach print checkmarked (and print set to be pdf under print format) - continue to get above error - smtplib.SMTPDataError: (501, b’Syntax error - line too long’).

Are there any further debugging steps? On the email side?

A recent post on a PDF related topic indicated that an update of wkhtmltopdf and openssl libraries contributed to a workable solution. Perhaps between the SMTPS and openssl modules, there might be a glitch or incompatibility?

Error seems repeated for HTML containing emails. I enabled a daily email report with sales invoices outstanding - and it too has same SMTP error.

Do I need to file a bug report somewhere?

Was able to resolve problem by migrating env back to python2.7. Problem remains unresolved for higher versions of python environment

Thanks zerodiscount - I just saw this, no note on python version nor traceback Customized Print Format Not showing properley when Attach document print in email · Issue #12455 · frappe/erpnext · GitHub

FWIW travis automated checkin tests run on 3.6

edit: correction apparently for now this runs 2.7

whereas this runs 2.7 and 3.6 Travis CI - Test and Deploy Your Code with Confidence

I tried 3.6 as well before reverting back to 2.7 - had same problem with 3.6. As I understand, the issue arises because HTML formatting needs an LF or CRLF - without which it seems to exceed the 1000 character limit for smtp… will stay on 2.7 until resolution (did so because of a discussion post where 3.5 seemed recommended for V11)

Tested again with v12.1.1 and Python3.6 - get same error. Seems unresolved as yet? Should revert back to Python2.7 as all email notifications with pdf attachments will not be sent…