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('[email protected],[email protected]")
        """
        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("[email protected],[email protected]" ,"你好,测试一下" ,"好好学习,天天向上" )

你可能感兴趣的:(python,django,脚本,ubuntu,Gmail)