20221217
This commit is contained in:
1 parent
84d41889d8
commit
4a0a92a532
2 files changed
+85
-32
No files matched your search
+79
-26
@@ -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",
|
||||
"<p>欢迎参加北京坤铭体质监测评估中心中医体质检测</p>\n",
|
||||
"<p><a href=\"{lianjie}\">点击参加测试</a></p>\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"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user