Gmail 发信,gmail发信,Python语言: Gm


Python语言: Gmail 发信

#coding:utf-8from email.mime.text import MIMETextimport smtplibclass 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" ,"你好,测试一下" ,"好好学习,天天向上" )

评论关闭