ex03.py

ex03.py — Python Source, 0Kb

ファイルコンテンツ

#!/usr/bin/env python
# ex03.py
# compose email message with French subject
# imports for python 2.4 ... see comments for python 2.5
import email.Utils           # email.utils
import email.MIMEText        # email.mime.text
import email.Header          # email.header
#
text = u"""\
Il s'agit d'un texte en fran\u00e7ais.
-- 
HAL 9000
"""
subject = u'Fran\u00e7ais'
sender = 'foo@example.com'
recipt = 'bar@example.jp'

hdr = email.Header.Header(subject, 'iso-8859-1')
msg = email.MIMEText.MIMEText(text, _charset='iso-8859-1')
msg['Subject'] = hdr
msg['From'] = sender
msg['To'] = recipt
msg['Date'] = email.Utils.formatdate(localtime=True)

print msg.as_string()