python发送邮件

# 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()

         

posted @ 2017-09-24 21:52  alsoalso  阅读(151)  评论(0编辑  收藏  举报