利用python发送每日邮件,或者警告信息。以下实例就是简单的发送邮件代码:
1、需要申请一个邮箱
2、开启邮箱的smtp的发送服务
#!/usr/bin/env python
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
sender = 'wzhwei_test@sina.com'
receiver = '***;***;***'
subject = 'python email test'
smtpserver = "smtp.sina.com"
username = "wzhwei_test@sina.com"
password = "******"
msg = MIMEText('<html><h1>你好</h1></html>','html','utf-8')
msg['Subject'] = subject
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()