diff -r ef03aff3b195 Doc/includes/email-rfc5322.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Doc/includes/email-rfc5322.py Thu Dec 22 10:14:41 2016 -0500 @@ -0,0 +1,26 @@ +# Import smtplib for the actual sending function +import smtplib + +# Import the email modules we'll need +from email.mime.text import MIMEText +from email.utils import formatdate +# Open a plain text file for reading. For this example, assume that +# the text file contains only ASCII characters. +fp = open(textfile, 'rb') +# Create a text/plain message +msg = MIMEText(fp.read()) +fp.close() + +# me == the sender's email address +# you == the recipient's email address +msg['Subject'] = 'The contents of %s' % textfile +msg['From'] = me +msg['To'] = you +msg['Date'] = formatdate(localtime=True) + +# Send the message via our own SMTP server, but don't include the +# envelope header. +s = smtplib.SMTP('localhost') +s.sendmail(me, [you], msg.as_string()) +s.quit() + diff -r ef03aff3b195 Doc/library/email-examples.rst --- a/Doc/library/email-examples.rst Wed Dec 21 23:43:50 2016 -0500 +++ b/Doc/library/email-examples.rst Thu Dec 22 10:14:41 2016 -0500 @@ -10,6 +10,9 @@ .. literalinclude:: ../includes/email-simple.py +The next one is a email following the minimal requirement of RFC5322: + +.. literalinclude:: ../includes/email-rfc5322.py And parsing RFC822 headers can easily be done by the parse(filename) or parsestr(message_as_string) methods of the Parser() class: