Attachment in mail changes filename when it resides in different path from source
kdasoulas opened this issue ยท 3 comments
Hello,
I have noticed an issue when you send an email (SMTP) with attachments and the files to be attached are not in the same directory where the python files are.
For example, if I want to attach an Excel file which is (in relation to my *.py files) in directory 'Reports/myreport.xlsx', the email is being sent correctly but the name of the Excel attached is renamed to 'Reportsmyreport.xlsx'.
To fix this issue in the providers directory in file email.py, we can change line 125 from:
part.add_header("Content-Disposition", "attachment", filename=attachment)
to:
part.add_header("Content-Disposition", "attachment", filename=attachment [attachment.rfind(re.findall(r'(/|\\)', attachment)[-1]) + 1 if len(re.findall(r'(/|\\)', attachment)) > 0 else 0:])
in order to take into account also possible Windows paths. Of course we also need to import re module.
Moreover, in the same file (email.py) there is a typo in line 73 ("parse" instead of "parsed").
Thank you.
Thanks for opening your first issue here! Be sure to follow the issue template! ๐๐๐
Thanks for reporting this!
I actually refactored this area in #267.
I believe this would address this issue as well.
Fixed in 1.2.0