def send_mail(subject,message):
SMTPserver = ‘qq 的 smtp server‘
sender = ‘[email protected]‘
password = "1234567"
To = [‘[email protected]‘,‘[email protected]‘]
#To = [‘[email protected]‘,]
Cc = [‘[email protected]‘,‘[email protected]‘]
msg = MIMEMultipart()
msg.attach(MIMEText(message, ‘html‘,‘UTF-8‘))
msg[‘Subject‘] = subject
msg[‘From‘] = sender
msg[‘To‘] = ",".join(To)
msg[‘Cc‘] = ‘,‘.join(Cc)
try:
mailserver = smtplib.SMTP(SMTPserver,25)
mailserver.login(sender,password)
mailserver.sendmail(sender,To,msg.as_string())
mailserver.quit()
print ‘send email success ‘
except smtplib.SMTPException:
print "Error: "
mes=open(‘redis_cluster.html‘,‘a+‘).read()
sub="Create valueadded cluster info "
send_mail(sub,mes)
原文:https://blog.51cto.com/19941018/2387001