diff options
author | R David Murray <rdmurray@bitdance.com> | 2016-09-07 21:15:59 -0400 |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2016-09-07 21:15:59 -0400 |
commit | 29d1bc0842e5b086813aa7de4ab18f1c192d2291 (patch) | |
tree | b812609f72f860adb5203ba9cbb1d0c4299e39af /Doc/includes/email-alternative-new-api.py | |
parent | 23e863378124229928e12b72c22df33f1428c61e (diff) | |
download | cpython-git-29d1bc0842e5b086813aa7de4ab18f1c192d2291.tar.gz |
#24277: The new email API is no longer provisional.
This is a wholesale reorganization and editing of the email documentation to
make the new API the standard one, and the old API the 'legacy' one. The
default is still the compat32 policy, for backward compatibility. We will
change that eventually.
Diffstat (limited to 'Doc/includes/email-alternative-new-api.py')
-rw-r--r-- | Doc/includes/email-alternative-new-api.py | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/Doc/includes/email-alternative-new-api.py b/Doc/includes/email-alternative-new-api.py deleted file mode 100644 index 321f727c31..0000000000 --- a/Doc/includes/email-alternative-new-api.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python3 - -import smtplib - -from email.message import EmailMessage -from email.headerregistry import Address -from email.utils import make_msgid - -# Create the base text message. -msg = EmailMessage() -msg['Subject'] = "Ayons asperges pour le déjeuner" -msg['From'] = Address("Pepé Le Pew", "pepe", "example.com") -msg['To'] = (Address("Penelope Pussycat", "penelope", "example.com"), - Address("Fabrette Pussycat", "fabrette", "example.com")) -msg.set_content("""\ -Salut! - -Cela ressemble à un excellent recipie[1] déjeuner. - -[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718 - ---Pepé -""") - -# Add the html version. This converts the message into a multipart/alternative -# container, with the original text message as the first part and the new html -# message as the second part. -asparagus_cid = make_msgid() -msg.add_alternative("""\ -<html> - <head></head> - <body> - <p>Salut!<\p> - <p>Cela ressemble à un excellent - <a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718> - recipie - </a> déjeuner. - </p> - <img src="cid:{asparagus_cid}" \> - </body> -</html> -""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html') -# note that we needed to peel the <> off the msgid for use in the html. - -# Now add the related image to the html part. -with open("roasted-asparagus.jpg", 'rb') as img: - msg.get_payload()[1].add_related(img.read(), 'image', 'jpeg', - cid=asparagus_cid) - -# Make a local copy of what we are going to send. -with open('outgoing.msg', 'wb') as f: - f.write(bytes(msg)) - -# Send the message via local SMTP server. -with smtplib.SMTP('localhost') as s: - s.send_message(msg) |