用python写传统的邮件
from email.mime.text import MIMEText
message = ''' hello jason
it is a test mail
please accept it'''
msg = MIMEText(message)
msg['To'] = 'xxxxx@qq.com'
msg['From'] = 'jason <mjzheng@xxxxx.com>'
msg['Subject'] = 'test mail'
print msg.as_string()
结果:
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
To: xxxxx@qq.com
From: jason <mjzheng@xxxxx.com>
Subject: test mail
hello jason
it is a test mail
please accept it
默认添加了3个头部Content-Type,MIME-Version,Content-Transfer-Encoding,而且也已经排好了版,这样的邮件,如果理解发送是可以的。如果想延迟发送的话,最好还是要加上Date和Message-ID头部,可以通过下面的方式来添加。
from email.mime.text import MIMEText
from email import Utils
message = ''' hello jason
it is a test mail
please accept it'''
msg = MIMEText(message)
msg['To'] = 'xxxxx@qq.com'
msg['From'] = 'jason <mjzheng@xxxxx.com>'
msg['Subject'] = 'test mail'
msg['Date'] = Utils.formatdate(localtime=1)
msg['Message-ID'] = Utils.make_msgid()
print msg.as_string()
结果:
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: