好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

自动发送邮件-2017-7-5

 #coding=utf-8
'''
Created on 2017-7-5
@auther:Qigege
Project: 发送邮箱测试

'''
import smtplib
from email.mime.text import MIMEText

#SMTP 服务器
mail_host= 'smtp.163测试数据'
mail_user= '******@163测试数据'
# 网易邮箱为网页版,需要用到客户端密码,进入网页版邮箱中设置授权码,即客户端密码
mail_password= '******'

# 发件人邮箱
sender= '******@163测试数据'
# 接收人邮箱
receiver=[ '******@qq测试数据', '******@qq测试数据']

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的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于自动发送邮件-2017-7-5的详细内容...

  阅读:38次