hotmail和QQ邮箱发信(python)
##Python语言: Hotmail 发信
#coding:utf-8
from email.mime.text import MIMEText
import smtplib
class Hotmail (object ):
    def __init__ (self ,account,password):
        self.account="%s@Hotmail.com" %account
        self.password=password
    def send (self ,to,title,content):
        print self.account,self.password
        server = smtplib.SMTP('smtp.live.com' )
##        server.set_debuglevel(1)
        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()
class QQMail(object ):
    def __init__ (self ,account,password):       
        self.account="%s@qq.com" %account
        self.password=password
    def send (self ,to,title,content):
        """
        send('zsp007@Hotmail.com,zsp747@Hotmail.com")
        """
        print self.account,self.password
        server = smtplib.SMTP('smtp.qq.com' )
        server.set_debuglevel(1)
##        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__" :    
    Hotmail=Hotmail("user" ,"pass")
    Hotmail.send("codemo@126.com","测试ok" ,"content" )
作者:代码示例
出处:http://codemo.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 
 
                     
                    
                 
                    
                 
                
             
         浙公网安备 33010602011771号
浙公网安备 33010602011771号