diff --git a/文件操作.ipynb b/文件操作.ipynb index 4949390..a631f01 100644 --- a/文件操作.ipynb +++ b/文件操作.ipynb @@ -388,10 +388,35 @@ { "cell_type": "code", "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "## 使用网易邮箱群发测试链接" + ] + }, + { + "cell_type": "code", + "execution_count": 6, "metadata": { + "execution": { + "iopub.execute_input": "2022-12-17T09:50:44.652147Z", + "iopub.status.busy": "2022-12-17T09:50:44.651632Z", + "iopub.status.idle": "2022-12-17T09:50:55.208581Z", + "shell.execute_reply": "2022-12-17T09:50:55.206883Z", + "shell.execute_reply.started": "2022-12-17T09:50:44.652098Z" + }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "邮件发送成功!\n", + "邮件发送成功!\n" + ] + } + ], "source": [ "from email.mime.text import MIMEText\n", "from email.mime.multipart import MIMEMultipart\n", @@ -402,37 +427,65 @@ "import time\n", "import re\n", "import json\n", + "import jwt\n", + "\n", + "key = \"Xixi1234\"\n", + "encoded = jwt.encode({\"email\": \"eygsoft@gmail.com\"}, key, algorithm='HS256')\n", + "#print(encoded)\n", "\n", "\n", - "\n", - "from_addr = 'kmingedu@163.com' #发件邮箱\n", - "password = 'GKWUZXMVYKSSUSSL' #邮箱密码\n", - "smtp_server = 'smtp.163.com' #SMTP服务器,以新浪为例\n", - "server = smtplib.SMTP(smtp_server,25) #第二个参数为默认端口为25,有些邮件有特殊端口\n", " \n", + "list1 = [\n", + " {'name':'lillianwong','E_mail':'lillianwong73@gmail.com'},\n", + " {'name':'杨玉冰','E_mail':'lkyyb@126.com'}]\n", "\n", - "fl_name = 'data/低碳院报告.json'\n", - "\n", - "with open(fl_name,'r') as fl:\n", - " m_xx = json.load(fl)\n", - "for k, v in m_xx.items():\n", - " m_bh = str(k).rjust(5,\"0\")\n", - " fl_name = f'file/220724/new/{m_bh}-{v[0]}.pdf'\n", - " fl = f'{m_bh}-{v[0]}.pdf'\n", - " m_rec = v[2]+'@ceic.com'\n", - " msg = MIMEMultipart()\n", - " msg['Subject'] = Header(\"低碳清洁能源研究院体质监测报告\",'utf-8')\n", - " msg['From'] = Header('北京坤铭体质监测评估中心')\n", - " msg['To'] = Header(m_rec)\n", "\n", + "for item in list1:\n", + " m_mail = item['E_mail']\n", + " m_name = item['name']\n", + " encoded = jwt.encode({\"email\": m_mail}, key, algorithm='HS256')\n", + " lianjie = f'https://www.forraid.com/survey/token/{encoded}/tcm0'\n", + " mail_msg = f\"\"\"\n", + "

欢迎参加北京坤铭体质监测评估中心中医体质检测

\n", + "

点击参加测试

\n", + "\"\"\"\n", " from_addr = 'kmingedu@163.com' #发件邮箱\n", " password = 'GKWUZXMVYKSSUSSL' #邮箱密码\n", - " to_addr = v[2] #收件邮箱\n", - " att1 =MIMEApplication(open(fl_name, 'rb').read())\n", - " #att1[\"Content-Type\"] = 'application/octet-stream'\n", - " # 这里的filename可以任意写,写什么名字,邮件中显示什么名字\n", - " att1.add_header('Content-Disposition','attachment',filename=fl)\n", - " print(m_bh,v[0],m_rec,fl)" + " smtp_server = 'smtp.163.com' #SMTP服务器,以新浪为例\n", + " server = smtplib.SMTP(smtp_server,25) #第二个参数为默认端口为25,有些邮件有特殊端口\n", + " msg = MIMEText(mail_msg, 'html', 'utf-8')\n", + " msg['Subject'] = Header(\"中医体质检测测试链接\",'utf-8')\n", + " msg['From'] = Header('北京坤铭体质监测评估中心')\n", + " msg['To'] = Header(m_mail)\n", + "\n", + " \n", + " to_addr = m_mail #收件邮箱\n", + " try:\n", + " server.login(from_addr,password) #登录邮箱\n", + " server.sendmail(from_addr,to_addr,msg.as_string()) #将msg转化成string发出\n", + " server.quit\n", + " time.sleep(5)\n", + " print('邮件发送成功!')\n", + " except smtplib.SMTPException:\n", + " print (\"Error: 无法发送邮件\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "try:\n", + " server.login(from_addr,password) #登录邮箱\n", + " server.sendmail(from_addr,to_addr,msg.as_string()) #将msg转化成string发出\n", + " server.quit\n", + " time.sleep(5)\n", + " print(f'{fl}邮件发送成功!')\n", + " except smtplib.SMTPException:\n", + " print (\"Error: 无法发送邮件\")\n", + " " ] }, { @@ -967,7 +1020,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, diff --git a/文件管理1.ipynb b/文件管理1.ipynb index e2d3e5d..650c382 100755 --- a/文件管理1.ipynb +++ b/文件管理1.ipynb @@ -650,15 +650,15 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 38, "id": "9957a90c-7735-4224-b5b5-4a4b1b7688c9", "metadata": { "execution": { - "iopub.execute_input": "2022-12-07T06:24:28.191719Z", - "iopub.status.busy": "2022-12-07T06:24:28.191155Z", - "iopub.status.idle": "2022-12-07T06:24:28.291897Z", - "shell.execute_reply": "2022-12-07T06:24:28.290876Z", - "shell.execute_reply.started": "2022-12-07T06:24:28.191671Z" + "iopub.execute_input": "2022-12-12T14:12:26.428992Z", + "iopub.status.busy": "2022-12-12T14:12:26.428458Z", + "iopub.status.idle": "2022-12-12T14:12:26.536571Z", + "shell.execute_reply": "2022-12-12T14:12:26.535612Z", + "shell.execute_reply.started": "2022-12-12T14:12:26.428944Z" }, "tags": [] },