Python Network Programming
by Abhishek Ratan, Eric Chou, Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker
How it works...
In this recipe, an email message is created in the send_email() function. This function is supplied with a Google account from where the email message will be sent. The message header object, msg, is created by calling the MIMEMultipart() class and then subject, recipient, and sender information is added on it.
Python's regular expression-handling module is used to filter the .gif image on the current path. The image attachment object, img, is then created with the MIMEImage() method from the email.mime.image module. A correct image header is added to this object and finally, the image is attached with the msg object created earlier. We can attach multiple image files within a for loop as shown in this recipe. We can also ...
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