ex03.py

ex03.py — Python Source, 0Kb

ファイルコンテンツ

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

-- 
HAL 90000
"""
subject = u'計算機です今日は'
sender = 'foo@example.jp'
recipt = 'tkikuchi@is.kochi-u.ac.jp' # <- 自分の id に変えること

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)

s = smtplib.SMTP('mail.is.kochi-u.ac.jp')
s.sendmail(sender, [recipt], msg.as_string())
s.close()