ยปCore Development>Code coverage>Doc/includes/email-mime.py

Python code coverage for Doc/includes/email-mime.py

#countcontent
1n/a# Import smtplib for the actual sending function
2n/aimport smtplib
3n/a
4n/a# And imghdr to find the types of our images
5n/aimport imghdr
6n/a
7n/a# Here are the email package modules we'll need
8n/afrom email.message import EmailMessage
9n/a
10n/a# Create the container email message.
11n/amsg = EmailMessage()
12n/amsg['Subject'] = 'Our family reunion'
13n/a# me == the sender's email address
14n/a# family = the list of all recipients' email addresses
15n/amsg['From'] = me
16n/amsg['To'] = ', '.join(family)
17n/amsg.preamble = 'Our family reunion'
18n/a
19n/a# Open the files in binary mode. Use imghdr to figure out the
20n/a# MIME subtype for each specific image.
21n/afor file in pngfiles:
22n/a with open(file, 'rb') as fp:
23n/a img_data = fp.read()
24n/a msg.add_attachment(img_data, maintype='image',
25n/a subtype=imghdr.what(None, img_data))
26n/a
27n/a# Send the email via our own SMTP server.
28n/awith smtplib.SMTP('localhost') as s:
29n/a s.send_message(msg)