[python]代码库
def sendEmail(content, title, from_name, from_address, to_address, serverport, serverip, username, password):
msg = MIMEText(content, _subtype='html', _charset='utf-8')
msg['Subject'] = Header(title, 'utf-8')
# 这里的to_address只用于显示,必须是一个string
msg['To'] = ','.join(to_address)
msg['From'] = from_name
try:
s = smtplib.SMTP_SSL(serverip, serverport)
s.login(username, password)
# 这里的to_address是真正需要发送的到的mail邮箱地址需要的是一个list
s.sendmail(from_address, to_address, msg.as_string())
print('%s----发送邮件成功' % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
except Exception as err:
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print(err)