码迷,mamicode.com
首页 > 编程语言 > 详细

python发送QQ邮箱方法

时间:2017-01-08 03:50:38      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:.com   port   log   color   端口   邮箱   email   ddr   import   

 1 import smtplib  
 2 from email.mime.text import MIMEText
 3 
 4 mail_user = "user1@qq.com"
 5 mail_pwd  = "password"
 6 mailto_list=["user2@qq.com", "user3@qq.com"]
 7 
 8 def send_mail(from_address, to_address_list, mail_subject, mail_content):
 9     msg = MIMEText(mail_content)
10     msg["Subject"] = mail_subject
11     msg[From] = from_address
12     msg[To] = ";".join(to_address_list)
13     
14     s = smtplib.SMTP("smtp.qq.com", timeout=30)#连接smtp邮件服务器,端口默认是25
15     #s = smtplib.SMTP_SSL("smtp.qq.com", 465)    #连接方法一
16     #s = smtplib.SMTP()    #连接方法二
17     #s.connect(mail_host)
18     s.login(from_address, mail_pwd)
19     s.sendmail(from_address, to_address_list, msg.as_string())
20     #s.quit()
21     s.close()
22 
23 send_mail(mail_user, mailto_list, 群发主题, 群发内容)

 

python发送QQ邮箱方法

标签:.com   port   log   color   端口   邮箱   email   ddr   import   

原文地址:http://www.cnblogs.com/hushaojun/p/6260651.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!