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: 无法发送邮件"