From 4b985d8388e279c3a15c92c7a61721d47f89c47f Mon Sep 17 00:00:00 2001 From: nfa Date: Thu, 23 Dec 2021 13:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'env/mail.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env/mail.py | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/env/mail.py b/env/mail.py index 591e738..0f26acf 100644 --- a/env/mail.py +++ b/env/mail.py @@ -1,28 +1,28 @@ -# -*- 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'],'测试邮件','测试邮件,以下是测试内容!') +# -*- 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 = 'Abc12345' # 发送者密码 + # 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'],'测试邮件','测试邮件,以下是测试内容!')