就是用的上面的模板,运行报错
from email.mime.text import MIMEText
from email.header import Header
import smtplib
import datetime
i=1
while 1>=0:
dt=datetime.datetime.now()
hour=dt.hour
minute=dt.minute
if hour>=0 or minute==10:
print('hello')
i=i+1
print(i)
print()
if i>=20:
break
if sendemail('hello','test') :
#if 1>0:
print('success')
else:
print('fail')
print('ok')
def sendemail(subject,text):
## 发送邮件
sender = '量化模拟盘<***@QQ.com>' #发送的邮箱
receiver = '***@QQ.com' #要接受的邮箱,多个地址用;隔开。经测试可以发送给别的QQ邮箱,至于其它Email地址没试
smtpserver = 'smtp.qq.com'
username = '***@qq.com' #你的邮箱账号
password = '***' #你的邮箱授权码。一个16位字符串
msg = MIMEText(text,'plain','utf-8') #中文需参数‘utf-8',单字节字符不需要
msg['Subject'] = Header(subject, 'utf-8')
msg['to'] = receiver
msg['from'] = sender #自己的邮件地址
server = smtplib.SMTP_SSL('smtp.qq.com')
#server.set_debuglevel(1) #打印调试信息
try :
#server.connect() # ssl无需这条
server.login(username, password) # 登陆
server.sendmail(sender, receiver, msg.as_string()) #发送
print('邮件发送成功')
except:
print('邮件发送失败')
server.quit() # 结束
2017-02-21