#coding=utf-8
'''
Created on 2017-7-5
@auther:Qigege
Project:发送邮箱测试
'''
import smtplib
from email.mime.text import MIMEText
#SMTP服务器
mail_host='smtp.163.com'
mail_user='******@163.com'
#网易邮箱为网页版,需要用到客户端密码,进入网页版邮箱中设置授权码,即客户端密码
mail_password='******'
#发件人邮箱
sender='******@163.com'
#接收人邮箱
receiver=['******@qq.com','******@qq.com']
content=u'邮箱测试......' #内容
title='Python SMTP Mail Test' #主题
message=MIMEText(content,'plain','utf-8')
#邮箱发送者地址
#格式化字符串format(),{}==%,例:‘{1},{0},{1}’.format('abc',12)-->'12,abc,12'
message['From']='{}'.format(sender)
#邮件接受者地址,字符串列表[‘接受地址1’,‘接受地址2’,......]或‘接受地址’
message['To']=','.join(receiver) #type(message['To'])为str
message['Subject']=title
try:
#启用SSL,端口一般是465
smtpObj=smtplib.SMTP_SSL(mail_host,465)
#登录验证
smtpObj.login(mail_user,mail_password)
#发送
smtpObj.sendmail(sender,receiver,message.as_string())
#as_string()将MIMEText或MIMEMultipart对象转换为str
print 'mail has been send successfully.'
except smtplib.SMTPException as e:
print e
登录后复制
以上就是自动发送邮件-2017-7-5的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2268698.html