`
zuroc
  • 浏览: 1312128 次
  • 性别: Icon_minigender_1
  • 来自: 江苏
社区版块
存档分类
最新评论

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.text import MIMEText
import smtplib

class Gamil (object ):
    def __init__ (self ,account,password):
        """
        Gamil("zsp007","xxxx")
        """
        self .account=" %s @gmail.com" %account
        self .password=password

    def send (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" ,"你好,测试一下" ,"好好学习,天天向上" )

3
2
分享到:
评论
3 楼 zuroc 2008-10-02  
他说的是一种协议
2 楼 woimovie 2008-10-02  
tls是什么?怎么用呢?
1 楼 est 2008-10-01  
Django里就比较简单了

钩上tls就可以用了 

相关推荐

Global site tag (gtag.js) - Google Analytics