Python小脚本:用Gmail发信
还发现了一个python的bug"""
A python module,definition or variable shouldn't be called email or mail.
"""
https://bugs.launchpad.net/ubuntu/+source/python2.5/+bug/144833
________________
#coding:utf-8
from email.mime.textimport MIMEText
import smtplib
classGamil(object):
def__init__(self,account,password):
"""
Gamil("zsp007","xxxx")
"""
self.account="%s@gmail.com"%account
self.password=password
defsend(self,to,title,content):
"""
send('zsp007@gmail.com,zsp747@gmail.com")
"""
server = smtplib.SMTP('smtp.gmail.com')
server.docmd("EHLO server")
server.starttls()
server.login(self.account,self.password)
msg = MIMEText(content)
msg['Content-Type']='text/plain; charset="utf-8"'
msg['Subject'] = title
msg['From'] = self.account
msg['To'] = to
server.sendmail(self.account, to ,msg.as_string())
server.close()
if__name__=="__main__":
gmail=Gamil("你的帐号","你的密码")
gmail.send("zsp007@gmail.com,zsp747@gmail.com","你好,测试一下","好好学习,天天向上")
页:
[1]