I looked through a lot of manuals, as well as another question here about stack overflow, and the documentation and explanation is at least just inexplicable code. I would like to send the file that I already have and send it as an attachment. I tried to copy and paste the code, but it does not work, so I can not fix this problem.
So I ask if anyone can find out who will explain how smtplib, as well as the email and MIME libraries work together to send a file, or rather how to do it using a zip file. Any help would be appreciated.
This is the code everyone is referring to:
import smtplib import zipfile import tempfile from email import encoders from email.message import Message from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart def send_file_zipped(the_file, recipients, sender=' you@you.com '): myzip = zipfile.ZipFile('file.zip', 'w')
I suspect the problem is that this code also zips up the file. I do not want to be silent, because I already have a zip file that I would like to send. In any case, this code is poorly documented, as well as the python libraries themselves, since they do not give any information about any past img files or text files.
UPDATE: The error I am getting now. I also updated what is in my file with the code above
Traceback (most recent call last): File "/Users/Zeroe/Documents/python_hw/cgi-bin/zip_it.py", line 100, in <module> send_file_zipped('hw5.zip', ' avaldez@oswego.edu ') File "/Users/Zeroe/Documents/python_hw/cgi-bin/zip_it.py", line 32, in send_file_zipped msg.set_payload(myzip.read()) TypeError: read() takes at least 2 arguments (1 given)
Andy
source share