Python email zip file


















Save Article. Like Article. Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics. Next zip in Python. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. How to send a zip file as an attachment in python?

Ask Question. Asked 9 years, 8 months ago. Active 5 months ago. Viewed 23k times. This is the code that everyone refers to: import smtplib import zipfile import tempfile from email import encoders from email. ZipFile 'file.

SMTP smtp. Andy Andy What code is not working in what way? This is You'll have to give some specifics to get any answer that won't be essentially be a copy of that sample. Its not a copy I am asking them to actually explain how it does what I need through a zip file. But I will post the same code everyone constantly refers to but does not explain Well then remove the part that would zip the file again from your code.

Why do you think that sending an existing zip file is any different from sending an existing img or text file? Show 10 more comments. Active Oldest Votes. The msg. Just open your zip file beforehand and let this line read from it. Andy: The docs indicate the second argument, charset , is optional.

I will show you the error I am getting and the updated code like you told me to probably do. I appreciate the help. I'd rather not do this and thought hoped I could simply use How can I access the archive without creating a.

Additionally, maybe I shouldn't even be using the email module only used it so I could easily find the attachment???

What you are probably looking for is the StringIO module, which wraps up a string to give it the interface of a file. Also, you need to decode the email attachment payload from base64 so that you are dealing with the correct bytes. Here is an example which unzips the attachment into the current working directory:.

If you want to specify a different path than the current directory for the unzipped files, you can specify that as a parameter to extractall :. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Python 2. Asked 8 years, 2 months ago. Active 8 years, 2 months ago.



0コメント

  • 1000 / 1000