ex02.py

ex02.py — Python Source, 0Kb

ファイルコンテンツ

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ex02.py
# 日本語の email メッセージ
import email.utils
import email.mime.text
import email.header
#
text = u"""\
このメールはプログラムで生成しています。

-- 
HAL 90000
"""
subject = u'計算機です今日は'
sender = 'foo@example.com'
recipt = 'bar@example.jp'

sbjhd = email.header.Header(subject, 'iso-2022-jp')
msg = email.mime.text.MIMEText(text.encode('iso-2022-jp'), 
                                  _charset='iso-2022-jp')
msg['Subject'] = sbjhd
msg['From'] = sender
msg['To'] = recipt
msg['Date'] = email.utils.formatdate(localtime=True)

print msg.as_string()