fyenne commited on
Commit
e5ce045
1 Parent(s): c50e8c0
Files changed (3) hide show
  1. mail_sender.py +41 -11
  2. pages/🎉p3.py +1 -1
  3. test.ipynb +74 -79
mail_sender.py CHANGED
@@ -33,12 +33,23 @@ class config():
33
  # ============================================================================ #
34
  # file #
35
  # ============================================================================ #
36
- output_name1 = 'name'
37
- # part1 = MIMEBase('application', "octet-stream")
38
  # part1.set_payload(payload)
39
- # encoders.encode_base64(part1)
40
- # part1.add_header('Content-Disposition', 'attachment', filename=('utf-8', '', output_name1))
41
- # msg.attach(part1)
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  # ============================================================================ #
44
  # config #
@@ -51,7 +62,7 @@ class config():
51
  server.sendmail(account, receivers, text)
52
 
53
 
54
- def run_(self, content , payload, receivers):
55
  self.server.starttls()
56
  self.server.login(self.mail, self.pw)
57
  print('connecting...')
@@ -66,14 +77,25 @@ class config():
66
  )
67
  if type(receivers) is list:
68
  for i in receivers:
69
- self.sendEmailwithFile(self.mail, server = self.server, content = content, payload=payload, receivers=i)
 
 
 
 
 
70
  print("SUCCESS", i)
71
  pass
 
72
  elif type(receivers) is str:
73
- self.sendEmailwithFile(self.mail, server = self.server, content = content, payload=payload, receivers=receivers)
 
 
 
 
 
74
  print("SUCCESS", receivers)
75
  else:
76
- raise Exception("mothenfuicker")
77
  except Exception as e:
78
  raise ValueError(e)
79
  self.server.quit()
@@ -81,5 +103,13 @@ class config():
81
 
82
 
83
 
84
- a = config()
85
- a.run_('a', payload=None, receivers='fyenne@hotmail.com')
 
 
 
 
 
 
 
 
 
33
  # ============================================================================ #
34
  # file #
35
  # ============================================================================ #
36
+ # output_name1 = 'name'
37
+ part1 = MIMEBase('application', "octet-stream")
38
  # part1.set_payload(payload)
39
+ part1.set_payload(open(payload, "rb").read())
40
+ encoders.encode_base64(part1)
41
+ try:
42
+ print(re.findall('\.\w+', payload.name))
43
+ except:
44
+ print(re.findall('?>=\.\w+', payload))
45
+ print(re.findall('\w+(?=\.\w+)', payload))
46
+ pass
47
+ output_name1 = re.findall('\w+(?=\.\w+)', payload)
48
+ part1.add_header('Content-Disposition', 'attachment', filename=('utf-8', '', payload))
49
+
50
+
51
+
52
+ msg.attach(part1)
53
 
54
  # ============================================================================ #
55
  # config #
 
62
  server.sendmail(account, receivers, text)
63
 
64
 
65
+ def run_(self, content, payload, receivers):
66
  self.server.starttls()
67
  self.server.login(self.mail, self.pw)
68
  print('connecting...')
 
77
  )
78
  if type(receivers) is list:
79
  for i in receivers:
80
+ self.sendEmailwithFile(
81
+ self.mail,
82
+ server = self.server,
83
+ content = content,
84
+ payload=payload,
85
+ receivers=i)
86
  print("SUCCESS", i)
87
  pass
88
+
89
  elif type(receivers) is str:
90
+ self.sendEmailwithFile(
91
+ self.mail,
92
+ server = self.server,
93
+ content = content,
94
+ payload=payload,
95
+ receivers=receivers)
96
  print("SUCCESS", receivers)
97
  else:
98
+ raise Exception("mothenfucker")
99
  except Exception as e:
100
  raise ValueError(e)
101
  self.server.quit()
 
103
 
104
 
105
 
106
+ # a = config()
107
+ # server = smtplib.SMTP("smtp.office365.com", 587)
108
+ # server.starttls()
109
+ # server.login(a.mail,a.pw)
110
+ # content = ''
111
+ # payload = r"C:\Users\dscshap3808\Documents\fapiao\202109.pdf"
112
+ # a.sendEmailwithFile(account=a.mail, server=server, content=content, payload=payload,
113
+ # receivers='siming.yan@sf-dsc.com')
114
+ # server.quit()
115
+ # a.run_('a', payload=None, receivers='fyenne@hotmail.com')
pages/🎉p3.py CHANGED
@@ -16,7 +16,7 @@ if add_plus is not None:
16
  select_list = ["fyenne@hotmail.com"]+ [str(add_plus)]
17
  else:
18
  select_list = ["fyenne@hotmail.com"]
19
- receiver = st.multiselect("to_whom", options = select_list)
20
  st.write(select_list)
21
 
22
  # try:
 
16
  select_list = ["fyenne@hotmail.com"]+ [str(add_plus)]
17
  else:
18
  select_list = ["fyenne@hotmail.com"]
19
+ receiver = st.multiselect("to_whom", options = select_list, default = 'fyenne@hotmail.com')
20
  st.write(select_list)
21
 
22
  # try:
test.ipynb CHANGED
@@ -2,7 +2,7 @@
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
- "execution_count": 4,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
@@ -48,7 +48,7 @@
48
  },
49
  {
50
  "cell_type": "code",
51
- "execution_count": 29,
52
  "metadata": {},
53
  "outputs": [],
54
  "source": [
@@ -57,7 +57,7 @@
57
  },
58
  {
59
  "cell_type": "code",
60
- "execution_count": 39,
61
  "metadata": {},
62
  "outputs": [],
63
  "source": [
@@ -66,37 +66,18 @@
66
  },
67
  {
68
  "cell_type": "code",
69
- "execution_count": 19,
70
  "metadata": {},
71
- "outputs": [
72
- {
73
- "data": {
74
- "text/plain": [
75
- "True"
76
- ]
77
- },
78
- "execution_count": 19,
79
- "metadata": {},
80
- "output_type": "execute_result"
81
- }
82
- ],
83
  "source": [
84
  "'ou_code' in list(a[0])"
85
  ]
86
  },
87
  {
88
  "cell_type": "code",
89
- "execution_count": 2,
90
  "metadata": {},
91
- "outputs": [
92
- {
93
- "name": "stdout",
94
- "output_type": "stream",
95
- "text": [
96
- "connecting...\n"
97
- ]
98
- }
99
- ],
100
  "source": [
101
  "\n",
102
  "import smtplib\n",
@@ -109,31 +90,87 @@
109
  },
110
  {
111
  "cell_type": "code",
112
- "execution_count": 9,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  "metadata": {},
114
  "outputs": [
115
  {
116
- "ename": "SMTPDataError",
117
- "evalue": "(554, b'5.2.0 STOREDRV.Submission.Exception:OutboundSpamException; Failed to process message due to a permanent exception with message [BeginDiagnosticData]WASCL UserAction verdict is not None. Actual verdict is Suspend, ShowTierUpgrade. OutboundSpamException: WASCL UserAction verdict is not None. Actual verdict is Suspend, ShowTierUpgrade.[EndDiagnosticData] [Hostname=DM5PR15MB1643.namprd15.prod.outlook.com]')",
118
  "output_type": "error",
119
  "traceback": [
120
  "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
121
- "\u001b[1;31mSMTPDataError\u001b[0m Traceback (most recent call last)",
122
- "\u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\test.ipynb Cell 3'\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000002?line=0'>1</a>\u001b[0m server\u001b[39m.\u001b[39;49msendmail(from_addr\u001b[39m=\u001b[39;49m \u001b[39m'\u001b[39;49m\u001b[39mfyenneyenn@hotmail.com\u001b[39;49m\u001b[39m'\u001b[39;49m, \n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000002?line=1'>2</a>\u001b[0m to_addrs\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mfyenne@hotmail.com\u001b[39;49m\u001b[39m'\u001b[39;49m, \n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000002?line=2'>3</a>\u001b[0m msg\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39maaaa\u001b[39;49m\u001b[39m'\u001b[39;49m)\n",
123
- "File \u001b[1;32mc:\\Users\\dscshap3808\\Miniconda3\\envs\\siming\\lib\\smtplib.py:890\u001b[0m, in \u001b[0;36mSMTP.sendmail\u001b[1;34m(self, from_addr, to_addrs, msg, mail_options, rcpt_options)\u001b[0m\n\u001b[0;32m 888\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 889\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_rset()\n\u001b[1;32m--> 890\u001b[0m \u001b[39mraise\u001b[39;00m SMTPDataError(code, resp)\n\u001b[0;32m 891\u001b[0m \u001b[39m#if we got here then somebody got our mail\u001b[39;00m\n\u001b[0;32m 892\u001b[0m \u001b[39mreturn\u001b[39;00m senderrs\n",
124
- "\u001b[1;31mSMTPDataError\u001b[0m: (554, b'5.2.0 STOREDRV.Submission.Exception:OutboundSpamException; Failed to process message due to a permanent exception with message [BeginDiagnosticData]WASCL UserAction verdict is not None. Actual verdict is Suspend, ShowTierUpgrade. OutboundSpamException: WASCL UserAction verdict is not None. Actual verdict is Suspend, ShowTierUpgrade.[EndDiagnosticData] [Hostname=DM5PR15MB1643.namprd15.prod.outlook.com]')"
125
  ]
126
  }
127
  ],
128
  "source": [
129
- "server.sendmail(from_addr= 'fyenneyenn@hotmail.com', \n",
130
- " to_addrs='fyenne@hotmail.com', \n",
131
- " msg='aaaa')"
 
 
 
 
 
132
  ]
133
  },
134
  {
135
  "cell_type": "code",
136
- "execution_count": 9,
137
  "metadata": {},
138
  "outputs": [],
139
  "source": [
@@ -161,48 +198,6 @@
161
  "# selected_page = st.sidebar.selectbox(\"Select a page\", page_names_to_funcs.keys())\n",
162
  "# page_names_to_funcs[selected_page]()\n"
163
  ]
164
- },
165
- {
166
- "cell_type": "code",
167
- "execution_count": 15,
168
- "metadata": {},
169
- "outputs": [
170
- {
171
- "ename": "ImportError",
172
- "evalue": "cannot import name 'config' from 'mail_sender' (c:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\mail_sender.py)",
173
- "output_type": "error",
174
- "traceback": [
175
- "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
176
- "\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
177
- "\u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\test.ipynb Cell 5'\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000004?line=0'>1</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mmail_sender\u001b[39;00m \u001b[39mimport\u001b[39;00m config\n",
178
- "\u001b[1;31mImportError\u001b[0m: cannot import name 'config' from 'mail_sender' (c:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\mail_sender.py)"
179
- ]
180
- }
181
- ],
182
- "source": [
183
- "from mail_sender import config"
184
- ]
185
- },
186
- {
187
- "cell_type": "code",
188
- "execution_count": 22,
189
- "metadata": {},
190
- "outputs": [
191
- {
192
- "data": {
193
- "text/plain": [
194
- "'htomails@hotms.com'"
195
- ]
196
- },
197
- "execution_count": 22,
198
- "metadata": {},
199
- "output_type": "execute_result"
200
- }
201
- ],
202
- "source": [
203
- "import re\n",
204
- "re.findall('\\w+\\@\\w+\\.\\w+', '[htomails@hotms.com]')[0]\n"
205
- ]
206
  }
207
  ],
208
  "metadata": {
 
2
  "cells": [
3
  {
4
  "cell_type": "code",
5
+ "execution_count": null,
6
  "metadata": {},
7
  "outputs": [],
8
  "source": [
 
48
  },
49
  {
50
  "cell_type": "code",
51
+ "execution_count": null,
52
  "metadata": {},
53
  "outputs": [],
54
  "source": [
 
57
  },
58
  {
59
  "cell_type": "code",
60
+ "execution_count": null,
61
  "metadata": {},
62
  "outputs": [],
63
  "source": [
 
66
  },
67
  {
68
  "cell_type": "code",
69
+ "execution_count": null,
70
  "metadata": {},
71
+ "outputs": [],
 
 
 
 
 
 
 
 
 
 
 
72
  "source": [
73
  "'ou_code' in list(a[0])"
74
  ]
75
  },
76
  {
77
  "cell_type": "code",
78
+ "execution_count": null,
79
  "metadata": {},
80
+ "outputs": [],
 
 
 
 
 
 
 
 
81
  "source": [
82
  "\n",
83
  "import smtplib\n",
 
90
  },
91
  {
92
  "cell_type": "code",
93
+ "execution_count": null,
94
+ "metadata": {},
95
+ "outputs": [],
96
+ "source": [
97
+ "try:\n",
98
+ " del config\n",
99
+ "except:\n",
100
+ " pass\n"
101
+ ]
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "execution_count": 1,
106
+ "metadata": {},
107
+ "outputs": [],
108
+ "source": [
109
+ "try:\n",
110
+ " del config\n",
111
+ "except:\n",
112
+ " pass\n",
113
+ "from mail_sender import config\n",
114
+ "import smtplib\n",
115
+ "from email.mime.multipart import MIMEMultipart\n",
116
+ "from email.mime.text import MIMEText \n",
117
+ "from email.mime.base import MIMEBase\n",
118
+ "from email import encoders"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": 2,
124
+ "metadata": {},
125
+ "outputs": [
126
+ {
127
+ "data": {
128
+ "text/plain": [
129
+ "<smtplib.SMTP at 0x2425836deb0>"
130
+ ]
131
+ },
132
+ "execution_count": 2,
133
+ "metadata": {},
134
+ "output_type": "execute_result"
135
+ }
136
+ ],
137
+ "source": [
138
+ "a = config()\n",
139
+ "a.server"
140
+ ]
141
+ },
142
+ {
143
+ "cell_type": "code",
144
+ "execution_count": 3,
145
  "metadata": {},
146
  "outputs": [
147
  {
148
+ "ename": "AttributeError",
149
+ "evalue": "'str' object has no attribute 'name'",
150
  "output_type": "error",
151
  "traceback": [
152
  "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
153
+ "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
154
+ "\u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\test.ipynb Cell 9\u001b[0m in \u001b[0;36m<cell line: 6>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=3'>4</a>\u001b[0m content \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39m'\u001b[39m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=4'>5</a>\u001b[0m payload \u001b[39m=\u001b[39m \u001b[39mr\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mC:\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mUsers\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mdscshap3808\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mDocuments\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mfapiao\u001b[39m\u001b[39m\\\u001b[39m\u001b[39m202109.pdf\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=5'>6</a>\u001b[0m a\u001b[39m.\u001b[39;49msendEmailwithFile(account\u001b[39m=\u001b[39;49ma\u001b[39m.\u001b[39;49mmail, server\u001b[39m=\u001b[39;49mserver, content\u001b[39m=\u001b[39;49mcontent, payload\u001b[39m=\u001b[39;49mpayload, \n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=6'>7</a>\u001b[0m receivers\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39msiming.yan@sf-dsc.com\u001b[39;49m\u001b[39m'\u001b[39;49m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Users/dscshap3808/Documents/my_scripts_new/stlit/test.ipynb#ch0000011?line=7'>8</a>\u001b[0m server\u001b[39m.\u001b[39mquit()\n",
155
+ "File \u001b[1;32mc:\\Users\\dscshap3808\\Documents\\my_scripts_new\\stlit\\mail_sender.py:41\u001b[0m, in \u001b[0;36mconfig.sendEmailwithFile\u001b[1;34m(self, account, server, content, payload, receivers)\u001b[0m\n\u001b[0;32m 39\u001b[0m part1\u001b[39m.\u001b[39mset_payload(\u001b[39mopen\u001b[39m(payload, \u001b[39m\"\u001b[39m\u001b[39mrb\u001b[39m\u001b[39m\"\u001b[39m)\u001b[39m.\u001b[39mread())\n\u001b[0;32m 40\u001b[0m encoders\u001b[39m.\u001b[39mencode_base64(part1)\n\u001b[1;32m---> 41\u001b[0m \u001b[39mprint\u001b[39m(re\u001b[39m.\u001b[39mfindall(\u001b[39m'\u001b[39m\u001b[39m\\\u001b[39m\u001b[39m.\u001b[39m\u001b[39m\\\u001b[39m\u001b[39mw+\u001b[39m\u001b[39m'\u001b[39m, payload\u001b[39m.\u001b[39;49mname))\n\u001b[0;32m 42\u001b[0m \u001b[39m# output_name1 = (payload)\u001b[39;00m\n\u001b[0;32m 43\u001b[0m part1\u001b[39m.\u001b[39madd_header(\u001b[39m'\u001b[39m\u001b[39mContent-Disposition\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mattachment\u001b[39m\u001b[39m'\u001b[39m, filename\u001b[39m=\u001b[39m(\u001b[39m'\u001b[39m\u001b[39mutf-8\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39m'\u001b[39m, payload\u001b[39m.\u001b[39mname))\n",
156
+ "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'name'"
157
  ]
158
  }
159
  ],
160
  "source": [
161
+ "server = smtplib.SMTP(\"smtp.office365.com\", 587)\n",
162
+ "server.starttls()\n",
163
+ "server.login(a.mail,a.pw)\n",
164
+ "content = ''\n",
165
+ "payload = r\"C:\\Users\\dscshap3808\\Documents\\fapiao\\202109.pdf\"\n",
166
+ "a.sendEmailwithFile(account=a.mail, server=server, content=content, payload=payload, \n",
167
+ " receivers='siming.yan@sf-dsc.com')\n",
168
+ "server.quit()"
169
  ]
170
  },
171
  {
172
  "cell_type": "code",
173
+ "execution_count": null,
174
  "metadata": {},
175
  "outputs": [],
176
  "source": [
 
198
  "# selected_page = st.sidebar.selectbox(\"Select a page\", page_names_to_funcs.keys())\n",
199
  "# page_names_to_funcs[selected_page]()\n"
200
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
202
  ],
203
  "metadata": {