Python发送邮件

来源:互联网 发布:pushkit python 编辑:程序博客网 时间:2024/05/18 22:40
# -*- coding: cp936 -*-# 甄码农,20120307import smtplibfrom email.mime.text import MIMEText mail_host = 'smtp.126.com'mail_user = 'xxx@126.com'mail_pwd = 'hellopwd'mail_to = 'xxao@gmail.com'mail_cc = 'xx@xx.com'mail_bcc = 'xx@qq.com'content = 'this is a mail sent with python' #表头信息msg = MIMEText(content)msg['From'] = mail_usermsg['Subject'] = 'this is a python test mail'msg['To'] = mail_tomsg['Cc'] = mail_ccmsg['Bcc'] = mail_bcctry:    s = smtplib.SMTP()    s.connect(mail_host)    #login    s.login(mail_user,mail_pwd)     #send mail    s.sendmail(mail_user,[mail_to,mail_cc,mail_bcc],msg.as_string())    s.close()    print 'success'except Exception ,e:    print e

0 0
原创粉丝点击