Python Forum
email attachement with non-ascii characters will be renamed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
email attachement with non-ascii characters will be renamed
#3
That is not possible - if I try to change line 27 to

msg.add_attachment(open(path, "r").read(), filename=file.encode('utf-8'))
then I only get a lot of error-messages like this:

C:\Users\ESchuett>"C:/Program Files (x86)/Python38-32/python.exe" g:/Posteingang/Python-Forum/sendmail_2020-04-07.py
Traceback (most recent call last):
File "g:/Posteingang/Python-Forum/sendmail_2020-04-07.py", line 27, in <module>
msg.add_attachment(open(path, "r").read(), filename=file.encode('utf-8')) # Attachement mit Umlaut wird umbenannt!
File "C:\Program Files (x86)\Python38-32\lib\email\message.py", line 1156, in add_attachment
self._add_multipart('mixed', *args, _disp='attachment', **kw)
File "C:\Program Files (x86)\Python38-32\lib\email\message.py", line 1144, in _add_multipart
part.set_content(*args, **kw)
File "C:\Program Files (x86)\Python38-32\lib\email\message.py", line 1171, in set_content
super().set_content(*args, **kw)
File "C:\Program Files (x86)\Python38-32\lib\email\message.py", line 1101, in set_content
content_manager.set_content(self, *args, **kw)
File "C:\Program Files (x86)\Python38-32\lib\email\contentmanager.py", line 37, in set_content
handler(msg, obj, *args, **kw)
File "C:\Program Files (x86)\Python38-32\lib\email\contentmanager.py", line 191, in set_text_content
_finalize_set(msg, disposition, filename, cid, params)
File "C:\Program Files (x86)\Python38-32\lib\email\contentmanager.py", line 118, in _finalize_set
msg.set_param('filename',
File "C:\Program Files (x86)\Python38-32\lib\email\message.py", line 731, in set_param
[ctype, _formatparam(param, value, requote)])
File "C:\Program Files (x86)\Python38-32\lib\email\message.py", line 59, in _formatparam
value.encode('ascii')
AttributeError: 'bytes' object has no attribute 'encode'
Reply


Messages In This Thread
RE: email attachement with non-ascii characters will be renamed - by Erich1959 - Apr-07-2020, 05:23 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020