机房环境监测服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.4 KiB

# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
import urllib.request
def sendmail(receiver, subject, content):
try:
email_host = 'smtp.sina.com' # 发送者是sina邮箱
email_user = 'xxxxx@sina.com' # 发送者账号
email_pwd = 'Wj12345' # 发送者密码
# maillist = 'test123@yeah.net' # 接收者账号,本来想写成[]list的,但是报错,还没解决!
# 三个参数:第一个为文本内容,第二个 html 设置文本格式,第三个 utf-8 设置编码
msg = MIMEText(content, 'html', 'utf-8') # 邮件内容
msg['Subject'] = subject # 邮件主题
msg['From'] = email_user # 发送者账号
msg['To'] = ','.join(receiver) # 接收者账号列表(列表没实现)
smtp = smtplib.SMTP(email_host) # 如上变量定义的,是163邮箱
smtp.login(email_user, email_pwd) # 发送者的邮箱账号,密码
smtp.sendmail(email_user, receiver, msg.as_string()) # 参数分别是发送者,接收者,第三个不知道
smtp.quit() # 发送完毕后退出smtp
return True
except:
return False
if __name__ == '__main__':
sendmail(['abc123@yeah.net','xxxxx@163.com','abc123@cz.gov.cn'],'测试邮件','测试邮件,以下是测试内容!')