MIME message generation with 8-bit headers : email « Network « Python Tutorial






from email.MIMEText import MIMEText
from email.Header import Header
from email import Utils
message = """Hello,
This is a test messaget!
-- Anonymous"""

msg = MIMEText(message)
msg['To'] = 'recipient@example.com'
fromhdr = Header("Michael M\xfcller", 'iso-8859-1')
fromhdr.append('<mmueller@example.com>', 'ascii')
msg['From'] = fromhdr
msg['Subject'] = Header('Test Message')
msg['Date'] = Utils.formatdate(localtime = 1)
msg['Message-ID'] = Utils.make_msgid()

print msg.as_string()








21.25.email
21.25.1.MIME message generation with 8-bit headers
21.25.2.# MIME Header Parsing
21.25.3.MIME Message Parsing
21.25.4.Message Generation with Date and Message-ID
21.25.5.Message Generation
21.25.6.Message Parsing