37,720
社区成员
发帖
与我相关
我的任务
分享
def sendmail(nick,title,content,tomail):
'''发送电子邮件'''
ziphanghao=[
["m02@sina.com","smtp.sina.com","123456"]
]
zhao=random.choice(ziphanghao) #随机获取一个发件帐号
MAIL_FROM=zhao[0]
MAIL_TO = tomail
msg = MIMEText(content,"html",_charset='utf-8')
msg['Subject'] = Header(title,'utf-8')
#h = Header(nick, 'utf-8')
#h.append("<"+MAIL_FROM+">","utf-8")
msg["From"]=MAIL_FROM
try:
smtp = smtplib.SMTP()
smtp.connect(zhao[1])
smtp.login(re.sub(r'\@[\w\-\.]+','',zhao[0]), zhao[2])#用户名和密码
smtp.sendmail(MAIL_FROM, MAIL_TO, msg.as_string())
return True
except Exception as e:
return False