This commit is contained in:
512song@sina.com committed 2022-07-28 08:57:03 +08:00
1 parent fdf955d282
commit 34c948fb58
2 files changed
+336 -60

No files matched your search

+131 -52
View File
@@ -282,6 +282,129 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 邮件管理"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 使用网易邮箱群发邮件"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from email.mime.text import MIMEText\n",
"from email.mime.multipart import MIMEMultipart\n",
"from email.mime.application import MIMEApplication\n",
"from email.header import Header\n",
"import smtplib\n",
"import requests\n",
"import time\n",
"import re\n",
"import json\n",
"\n",
"\n",
" \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",
" \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",
" msg = MIMEMultipart()\n",
" msg['Subject'] = Header(\"低碳清洁能源研究院体质监测报告\",'utf-8')\n",
" msg['From'] = Header('北京坤铭体质监测评估中心')\n",
" msg['To'] = Header(m_rec)\n",
"\n",
" from_addr = 'kmingedu@163.com' #发件邮箱\n",
" password = 'GKWUZXMVYKSSUSSL' #邮箱密码\n",
" to_addr = m_rec #收件邮箱\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",
" msg.attach(att1)\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(f'{fl}邮件发送成功!')\n",
" except smtplib.SMTPException:\n",
" print (\"Error: 无法发送邮件\")\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from email.mime.text import MIMEText\n",
"from email.mime.multipart import MIMEMultipart\n",
"from email.mime.application import MIMEApplication\n",
"from email.header import Header\n",
"import smtplib\n",
"import requests\n",
"import time\n",
"import re\n",
"import json\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",
"\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",
" 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)"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -419,17 +542,9 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Topic List: ['arn:aws:sns:us-east-1:915521803346:MyTopic', 'arn:aws:sns:us-east-1:915521803346:dynamodb']\n"
]
}
],
"outputs": [],
"source": [
"import boto3\n",
"\n",
@@ -521,17 +636,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'low': Decimal('1.29'), 'code': 'USDCAD', 'high': Decimal('1.32')}\n"
]
}
],
"outputs": [],
"source": [
"import boto3\n",
"# Get the service resource.\n",
@@ -569,29 +676,9 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ResponseMetadata': {'RequestId': 'LCHMG55BG6A89FF2KBSDM7JRHNVV4KQNSO5AEMVJF66Q9ASUAAJG',\n",
" 'HTTPStatusCode': 200,\n",
" 'HTTPHeaders': {'server': 'Server',\n",
" 'date': 'Thu, 30 Sep 2021 05:04:36 GMT',\n",
" 'content-type': 'application/x-amz-json-1.0',\n",
" 'content-length': '2',\n",
" 'connection': 'keep-alive',\n",
" 'x-amzn-requestid': 'LCHMG55BG6A89FF2KBSDM7JRHNVV4KQNSO5AEMVJF66Q9ASUAAJG',\n",
" 'x-amz-crc32': '2745614147'},\n",
" 'RetryAttempts': 0}}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import boto3\n",
"import decimal\n",
@@ -612,17 +699,9 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Received and deleted message: {'MessageId': 'ecd656af-72e2-4bfc-9deb-3043dbe1bb80', 'ReceiptHandle': 'AQEBTx6u3PRfCgUy0SfLyOZcsD4fa5ge7AZvDTeQ/P4sOslg+sDMRYDZelJQOvxDK2XsLvy24DvD/n6GxBa2RwN55b/bnN7PxeYvv42d8GgkIy1dOPEBTytVKNIf+Z7t9+jMZMT2kq2ypXSa7jLFPFN00ArUkd0GI7nZ5SIS133s8exP46gRUGjgaS04CzAwPocTpWNt9GZpA114bvlicx2gNMYTIBsF65K2MzcyBoNVjLzmSJ1Pi0OCcQrAYaHvwzfnkriOBJLUX8BU4ksjWGJg0m8wh8hlPVMTLX+qxMneLzLawbf3cM/ricQR1XtooXrhsAuwAXA+VXaq5TzlpFJZaDZu5BvebF0Yj3rst7j54L/O3DwY0WfVmIrgv2yjOqL7', 'MD5OfBody': '9794e060a0eae4992dbf298549c42dc5', 'Body': 'https://sqs.us-east-1.amazonaws.com/915521803346/MySqs1', 'Attributes': {'SentTimestamp': '1632980620260'}}\n"
]
}
],
"outputs": [],
"source": [
"import boto3\n",
"\n",