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 attach a plain text attachment in a similar way.

To send the email message, we create an SMTP session. We call some testing method on this session object, such as ehlo() or starttls(). Then, log in to the Google SMTP server with a username and password and a sendmail() method is called to send the email.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.147.193