#!/usr/bin/env python
# -*- coding:UTF-8 -*-
#需要在邮箱处设置开启SMTP服务(第三方客户端发送)
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
def mail():
ret = True
try:
msg = MIMEText('测试邮件','plain','utf-8')
msg['From'] = formataddr(['18664988372','18664988372@163.com'])
msg['To'] = formataddr(['18664988372','18664988372@163.com'])
msg['Subject'] = '主题'


server = smtplib.SMTP("smtp.163.com",25)
server.login("18664988372@163.com",'wasver60')  #wasver60是授权第三方登录的密码
server.sendmail("18664988372@163.com",["18664988372@163.com",],msg.as_string())
server.quit()
except Exception:
ret = False
return ret

result = mail()
if result == True:
print ("邮件发送成功")
else:
print ("邮件发送失败")


posted on 2016-05-01 09:12  Alex0425  阅读(186)  评论(0编辑  收藏  举报