smtp邮件测试
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了smtp邮件测试相关的知识,希望对你有一定的参考价值。
# -*- coding:utf-8 -*-
#!/usr/bin/python
import sys
reload(sys) # reload 才能调用 setdefaultencoding 方法
sys.setdefaultencoding(‘utf-8‘) # 设置 ‘utf-8‘
import smtplib
from email.mime.text import MIMEText
from email.header import Header
#第三方服务smtp
mail_host=‘smtp.yeah.net‘
mail_user=‘xxx‘
mail_pass=‘xxx‘
mail_postfix= ‘yeah.net‘
receivers=‘[email protected]‘
def send_mail():
me = mail_user+"<"+mail_user+"@"+mail_postfix+">" #邮件发送方
subject = "Python SMTP 邮件测试test"
message = MIMEText(‘Python 邮件发送测试...‘, ‘plain‘, ‘utf-8‘) #邮件内容
message[‘subject‘] = subject #邮件标题
message[‘from‘] = me #发送方
message[‘to‘] = receivers #接收方
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host) #连接smtp
smtpObj.login(mail_user,mail_pass) #登录
smtpObj.sendmail(me,receivers, message.as_string()) #获取参数发送邮件
smtpObj.close() #关闭
print "邮件发送成功"
except smtplib.SMTPException,e:
print "ERROR,无法发送邮件"
print e
if __name__=="__main__":
send_mail()
以上是关于smtp邮件测试的主要内容,如果未能解决你的问题,请参考以下文章
foxmail测试结果为登陆到发送邮件服务器(smtp):smtp server reply:535 authentic
Python3+HTMLTestRunner+SMTP生成测试报告后发送邮件