Python2.7.8第三方邮件服务商的 SMTP 测试访问

#-*- coding:utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

mail_host = "smtp.yeah.net"
mail_user = "发送邮件的邮箱账号名(不加@xxx什么鬼的)"
mail_pass = "发送邮件的邮箱密码"

sender = '发送邮件的邮箱全名(包括@xxx什么鬼的)'
receivers = ['接收邮件的邮箱地址全称(xxx@xxx.xxx)']

message = MIMEText('Py mail test','plain','utf-8')
message['From'] = Header("Test","utf-8")
message['To'] = Header("测试",'utf-8')

subject = 'Py SMTP Test'
message['Subject'] = Header(subject,'utf-8')


try:
    smtpObj = smtplib.SMTP()
    smtpObj.connect(mail_host,25)
    smtpObj.login(mail_user,mail_pass)
    smtpObj.sendmail(sender,receivers,message.as_string())
    print "发送成功"

except smtplib.SMTPException:
    print "Error: 无法发送邮件"

Python2.7.8第三方邮件服务商的 SMTP 测试访问

上一篇:微服务引擎的线上流量治理最佳实践


下一篇:零基础容器技术实战——冬季实战营第四期学习报告