Problem with ASCII in E-Mail name

Hi, I also got the same issue.
I’m using G-mail with App Password
ERPNext: v12.3.1 (version-12)
Frappe Framework: v12.1.0 (version-12)
‘ascii’ codec can’t encode characters in position 42981-43013: ordinal not in range(128)
Traceback (most recent call last):
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/”, line 415, in send_one
smtpserver.sess.sendmail(email.sender, recipient.recipient, message)
File “/usr/lib/python3.6/”, line 855, in sendmail
msg = _fix_eols(msg).encode(‘ascii’)
UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 42981-43013: ordinal not in range(128)


Traceback (most recent call last):
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/doctype/email_account/”, line 280, in receive
communication = self.insert_communication(msg, args=args)
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/doctype/email_account/”, line 337, in insert_communication
email = Email(raw)
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/”, line 372, in init
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/”, line 393, in parse
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/”, line 445, in process_part
self.text_content += self.get_payload(part)
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/”, line 492, in get_payload
charset = self.get_charset(part)
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/”, line 487, in get_charset
charset = chardet.detect(part.encode())[‘encoding’]
AttributeError: ‘Message’ object has no attribute ‘encode’


{‘method_name’: ‘pull_from_email_account’, ‘log’: <function log at 0x7f64821ead90>, ‘retry’: 0, ‘is_async’: True, ‘user’: ‘Administrator’, ‘kwargs’: {‘email_account’: ‘Email Name’}, ‘job_name’: ‘pull_from_email_account|Email Name’, ‘event’: ‘all’, ‘method’: <function pull_from_email_account at 0x7f64820f17b8>, ‘site’: ‘site1.local’}
Traceback (most recent call last):
File “/home/seperp/frappe-bench/apps/frappe/frappe/utils/”, line 99, in execute_job
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/doctype/email_account/”, line 724, in pull_from_email_account
File “/home/seperp/frappe-bench/apps/frappe/frappe/email/doctype/email_account/”, line 303, in receive
raise Exception(frappe.as_json(exceptions))
Exception: [
“Traceback (most recent call last):\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/doctype/email_account/", line 280, in receive\n communication = self.insert_communication(msg, args=args)\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/doctype/email_account/", line 337, in insert_communication\n email = Email(raw)\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/", line 372, in init\n self.parse()\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/", line 393, in parse\n self.process_part(part)\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/", line 445, in process_part\n self.text_content += self.get_payload(part)\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/", line 492, in get_payload\n charset = self.get_charset(part)\n File "/home/seperp/frappe-bench/apps/frappe/frappe/email/", line 487, in get_charset\n charset = chardet.detect(part.encode())[‘encoding’]\nAttributeError: ‘Message’ object has no attribute ‘encode’\n”

@Mario_Truss Have you also been dealing with this problem?

I fixed the problem so:
change /home/frappe/frappe-bench/apps/frappe/frappe/email/

in 415 line i’am changed the value
smtpserver.sess.sendmail(email.sender, recipient.recipient, message)
smtpserver.sess.sendmail(email.sender, recipient.recipient, message.encode('utf-8'))

and restart supervisor

Thank you for your proposed solution. I will have this tested on our system some time soon.
@milkrage can you create a PR for this matter on github?


It’s fix works for you?
I won’t know how to make (right) pull request on GitHub :roll_eyes:

A fix was pushed for this some days back: fix(email): safe_encode to avoid smtp ascii encoding issue by Thunderbottom · Pull Request #9190 · frappe/frappe · GitHub.

It is currently merged in develop and v12 hotfix branch


No, I haven’t tested that yet. I might get a chance to do that this afternoon.

Hmm that merge actually isn’t quite right as the tests were fudged to pass.

Based on the first thread somehow that email address was entered all funny? Did someone manually do that or the system did?

this has been fixed in Version 12.4.


1 Like