Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
We have used Python's zipfile, smtplib, and an email module to achieve our objective of emailing a folder as a zipped archive. This is done using the email_dir_zipped() method. This method takes two arguments: the sender and recipient's email addresses to create the email message.
In order to create a ZIP archive, we create a temporary file with the tempfile module's TemporaryFile() class. We supply a filename, prefix, mail, and suffix, .zip. Then, we initialize the ZIP archive object with the ZipFile() class by passing the temporary file as its argument. Later, we add files of the current directory with the ZIP object's write() method call.
To send an email, we create a multipart MIME message with the MIMEmultipart() class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access