• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python实现给qq邮箱发送邮件的方法

python 搞代码 4年前 (2022-01-09) 23次浏览 已收录 0个评论

本文实例讲述了Python实现给qq邮箱发送邮件的方法。分享给大家供大家参考。具体实现方法如下:

#-*-coding:utf-8-*-  #========================================== # 导入smtplib和MIMEText #========================================== from email.mime.text import MIMEText import smtplib #========================================== # 要发给谁,这里发给2个人 #========================================== mailto_list=["[email protected]","[email protected]"] #========================================== # 设置服务器,用户名、口令以及邮箱的后缀 #========================================== mail_host="smtp.qq.com" mail_user="naughty610" mail_pass="here is your password" mail_postfix="qq.com" #========================================== # 发送邮件 #========================================== def send_mail(to_list,sub,content):   '''''   to_list:发给谁   sub:主题   content:内容   send_mail("[email protected]","sub","content")   '''   me=mail_user+""   msg = MIMEText(content)   msg['Subject'] = sub   msg['From'] = me   msg['To'] = ";".join(to_list)   try:     s = smtplib.SMTP()     s.connect(mail_host)     s.login(mail_user,mail_pass)     s.sendmail(me, to_list, msg.as_string())     s.close()     return True   exce<div>本文来源gaodai^.ma#com搞#代!码网</div>pt Exception, e:     print str(e)     return False if __name__ == '__main__':   if send_mail(mailto_list,"here is subject","here is content"):     print "发送成功"   else:     print "发送失败"

希望本文所述对大家的Python程序设计有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python实现给qq邮箱发送邮件的方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址