Email error when sending

Good day all

I have managed to sort out a few problems with my mail : gmail authentication, default mail etc…

But I am stuck on this one. I will copy the error-log entry and if I look at some of the orther posts of the
forum, then this might be an install issue.

One of them is linked below …

but the error is not quite the same as mine.

My installation is on a Digital Ocean droplet
ERPNext: v12.10.1 (version-12)

Frappe Framework: v12.8.4 (version-12)

done with a script install.
I looked at two links to do the install:

I am going to try and paste the entry into the error log here…
the one error entry is

{

“attachments”: ,
“bcc”: ,
“cc”: ,
“communication_name”: “73ea94747f”,
“lang”: “en”,
“print_format”: “Standard”,
“print_html”: “”,
“recipients”: [
“jlongland@webafrica.org.za”
]
}
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 500, in sendmail
recipients=recipients, cc=cc, bcc=bcc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/communication.py”, line 209, in _notify
_notify(self, print_html, print_format, attachments, recipients, cc, bcc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 173, in _notify
print_letterhead=frappe.flags.print_letterhead
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 487, in sendmail
inline_images=inline_images, header=header, print_letterhead=print_letterhead)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 162, in send
print_letterhead=print_letterhead)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 183, in add
email_queue = get_email_queue(recipients, sender, subject, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 218, in get_email_queue
header=kwargs.get(‘header’))
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 33, in get_email
emailobj = EMail(sender, recipients, subject, reply_to=reply_to, cc=cc, bcc=bcc, email_account=email_account, expose_recipients=expose_recipients)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 75, in init
self.msg_root = MIMEMultipart(‘mixed’, policy=policy.SMTPUTF8)
File “/usr/lib/python3.5/email/mime/multipart.py”, line 36, in init
MIMEBase.init(self, ‘multipart’, _subtype, **_params)
File “/usr/lib/python3.5/email/mime/base.py”, line 25, in init
self.add_header(‘Content-Type’, ctype, **_params)
File “/usr/lib/python3.5/email/message.py”, line 541, in add_header
parts.append(formatparam(k.replace('', ‘-’), v))
File “/usr/lib/python3.5/email/message.py”, line 49, in _formatparam
if value is not None and len(value) > 0:
TypeError: object of type ‘EmailPolicy’ has no len()

the other erro rentry is …

{‘retry’: 0, ‘kwargs’: {‘attachments’: , ‘print_letterhead’: 1, ‘cc’: , ‘lang’: ‘en’, ‘recipients’: [‘jlongland@webafrica.org.za’], ‘session’: {‘data’: {‘user_type’: ‘System User’, ‘csrf_token’: ‘6deb98cc1562390557a1c5b2fb3b02c7f808e50bda8af09fa21c29a9’, ‘lang’: ‘en’, ‘session_country’: {‘iso_code’: ‘ZA’, ‘names’: {‘ja’: ‘南アフリカ’, ‘en’: ‘South Africa’, ‘es’: ‘Sudáfrica’, ‘de’: ‘Südafrika’, ‘ru’: ‘ЮАР’, ‘fr’: ‘Afrique du Sud’, ‘zh-CN’: ‘南非’, ‘pt-BR’: ‘África do Sul’}, ‘geoname_id’: 953987}, ‘user’: ‘Administrator’, ‘last_updated’: ‘2020-08-12 20:41:13.047209’, ‘session_expiry’: ‘06:00:00’, ‘full_name’: None, ‘session_ip’: ‘156.155.218.175’, ‘device’: ‘desktop’}, ‘user’: ‘Administrator’, ‘sid’: ‘7994b24c8dd403a479ba3290689191678a4bf9bce0b3c333f1d29927’}, ‘print_format’: ‘Standard’, ‘bcc’: , ‘print_html’: ‘’, ‘communication_name’: ‘73ea94747f’}, ‘method_name’: ‘sendmail’, ‘job_name’: ‘<function sendmail at 0x7f7d157e7510>’, ‘event’: ‘sendmail’, ‘log’: <function log at 0x7f7b9a876510>, ‘is_async’: True, ‘user’: ‘Administrator’, ‘method’: <function sendmail at 0x7f7b9a751950>, ‘site’: ‘site1.local’}
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py”, line 102, in execute_job
method(**kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 500, in sendmail
recipients=recipients, cc=cc, bcc=bcc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/communication.py”, line 209, in _notify
_notify(self, print_html, print_format, attachments, recipients, cc, bcc)
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/communication/email.py”, line 173, in _notify
print_letterhead=frappe.flags.print_letterhead
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 487, in sendmail
inline_images=inline_images, header=header, print_letterhead=print_letterhead)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 162, in send
print_letterhead=print_letterhead)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 183, in add
email_queue = get_email_queue(recipients, sender, subject, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py”, line 218, in get_email_queue
header=kwargs.get(‘header’))
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 33, in get_email
emailobj = EMail(sender, recipients, subject, reply_to=reply_to, cc=cc, bcc=bcc, email_account=email_account, expose_recipients=expose_recipients)
File “/home/frappe/frappe-bench/apps/frappe/frappe/email/email_body.py”, line 75, in init
self.msg_root = MIMEMultipart(‘mixed’, policy=policy.SMTPUTF8)
File “/usr/lib/python3.5/email/mime/multipart.py”, line 36, in init
MIMEBase.init(self, ‘multipart’, _subtype, **_params)
File “/usr/lib/python3.5/email/mime/base.py”, line 25, in init
self.add_header(‘Content-Type’, ctype, **_params)
File “/usr/lib/python3.5/email/message.py”, line 541, in add_header
parts.append(formatparam(k.replace('', ‘-’), v))
File “/usr/lib/python3.5/email/message.py”, line 49, in _formatparam
if value is not None and len(value) > 0:
TypeError: object of type ‘EmailPolicy’ has no len()


If someone can help I would appreciate it !
Thanks for your time.

Good day all

I would like to add additional information.
I have googled further on this issue and found a post with a similar error.
It was however someone that was working on “Leave” in ERPNext.

What is notable, is that towards the end of the post below, was an entry of
someone that picked up a similar error when sending mail ( like I do )
AFTER UPGRADING FROM V11 TO V12.

My question therefor, : is this an issue only with V12?

The post …

Is it possible to get the opinion of one of the developers about this?

Many thanks !

Good day all

SOLVED

I have found a thread about a fix for this. I replaced the code in email_body.py.
Read the link below.

When I send a purchase order to a supplier it now works !

Best

I got around this by upgrading python version to 3.7 and migrating the environment accordingly:

  1. Upgrade to python 3.7
  2. bench migrate-env python3.7
  • Better than editing the core code

Cheers