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

python发送邮件

时间:2017-09-24 23:26:11      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:images   host   手机   ext   style   连接   text   第三方   163邮箱   

# send_mail.py

#coding:utf-8

import smtplib

from email.mime.text import MIMEText

from email.header import Header

# 第三方 SMTP 服务
mail_host="smtp.qq.com" #设置服务器,QQ邮箱、163邮箱(smtp.163.com)、自建邮箱

mail_user="用户名" #用户名

mail_pass="授权码" #口令,QQ邮箱/163邮箱是输入授权码,如下图在邮箱设置中 用验证过的手机发送短信获得,不含空格。

技术分享

技术分享

sender = ‘发件人qq.com‘ # 发件人


receivers = [‘收件人1@qq.com‘,‘收件人2@163.com‘,‘收件人3@xx.com‘] # 收件人

# 发送邮件主题


subject = ‘python email test‘

# 编写HTML类型的邮件正文


msg = MIMEText(‘<html><h1>你好!</h1></html>‘,‘html‘,‘utf-8‘)


msg[‘Subject‘] = Header(subject,‘utf-8‘)


msg[‘From‘] = ‘发件人@qq.com‘


msg[‘To‘] = ‘收件人1@qq.com,收件人2@163.com‘

msg[‘Cc‘] = ‘收件人3@xx.com‘ 

# 连接发送邮件


smtpObj = smtplib.SMTP_SSL(mail_host)


smtpObj.login(mail_user,mail_pass)


smtpObj.sendmail(sender, receivers, msg.as_string())


smtpObj.quit()

         

python发送邮件

标签:images   host   手机   ext   style   连接   text   第三方   163邮箱   

原文地址:http://www.cnblogs.com/sgwjj/p/7588875.html

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