Upload 4 files
Browse files
ap.py
CHANGED
@@ -6,6 +6,9 @@ from email.mime.base import MIMEBase
|
|
6 |
from email import encoders
|
7 |
import requests
|
8 |
import base64
|
|
|
|
|
|
|
9 |
|
10 |
# Encode the image to Base64
|
11 |
def get_base64_image(image_path):
|
@@ -17,23 +20,23 @@ def get_base64_image(image_path):
|
|
17 |
# Define your Slack email addresses and webhook URLs
|
18 |
Slack_email_addresses = {
|
19 |
'Rahul Mandowara': '[email protected]',
|
20 |
-
'Abhimanyu':'[email protected]',
|
21 |
-
'
|
22 |
-
'
|
23 |
'Priyanshi Nahata': '[email protected]',
|
24 |
-
'
|
25 |
'Bhavin Parmar': '[email protected]',
|
26 |
-
'
|
27 |
'Roshani Mohan': '[email protected]',
|
28 |
-
'
|
29 |
'Abhilash Sawant': '[email protected]',
|
30 |
'Hemant Yadav': '[email protected]',
|
31 |
-
'
|
32 |
-
'
|
33 |
-
'
|
34 |
'Shweta Kanungo': '[email protected]',
|
35 |
-
'
|
36 |
-
'Rasika': '[email protected]',
|
37 |
'Bhushan Khapare': '[email protected]',
|
38 |
'Vaibhavi':'[email protected]',
|
39 |
'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
|
@@ -45,22 +48,22 @@ Slack_email_addresses = {
|
|
45 |
gmail_addresses = {
|
46 |
'Rahul Mandowara': '[email protected]',
|
47 |
'Abhimanyu':'[email protected]',
|
48 |
-
'
|
49 |
-
'
|
50 |
-
'
|
51 |
'Priyanshi Nahata': '[email protected]',
|
52 |
-
'
|
53 |
'Bhavin Parmar': '[email protected]',
|
54 |
-
'
|
55 |
'Roshani Mohan': '[email protected]',
|
56 |
'Abhilash Sawant': '[email protected]',
|
57 |
'Hemant Yadav': '[email protected]',
|
58 |
-
'
|
59 |
-
'
|
60 |
-
'
|
61 |
'Shweta Kanungo': '[email protected]',
|
62 |
-
'
|
63 |
-
'Rasika': '[email protected]',
|
64 |
'Bhushan Khapare': '[email protected]',
|
65 |
'Vaibhavi': '[email protected]',
|
66 |
'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
|
@@ -71,30 +74,30 @@ gmail_addresses = {
|
|
71 |
}
|
72 |
|
73 |
Webhook_urls = {
|
74 |
-
'Rahul Mandowara':
|
75 |
-
'Abhimanyu':
|
76 |
-
'
|
77 |
-
'
|
78 |
-
'Priyanshi Nahata':
|
79 |
-
'
|
80 |
-
'Bhavin Parmar':
|
81 |
-
'
|
82 |
-
'Roshani Mohan':
|
83 |
-
'
|
84 |
-
'Abhilash Sawant':
|
85 |
-
'Hemant Yadav':
|
86 |
-
'
|
87 |
-
'
|
88 |
-
'
|
89 |
-
'Shweta Kanungo':
|
90 |
-
'
|
91 |
-
'Rasika':
|
92 |
-
'Bhushan Khapare':
|
93 |
-
'Vaibhavi':
|
94 |
-
'daily-alerts-for-unsubscribed-companies':
|
95 |
-
'finance_team_internal':
|
96 |
-
'valyx-fynd-poc':
|
97 |
-
'valyx_auto_invoices':
|
98 |
}
|
99 |
|
100 |
# Define your email server details
|
|
|
6 |
from email import encoders
|
7 |
import requests
|
8 |
import base64
|
9 |
+
import os
|
10 |
+
|
11 |
+
|
12 |
|
13 |
# Encode the image to Base64
|
14 |
def get_base64_image(image_path):
|
|
|
20 |
# Define your Slack email addresses and webhook URLs
|
21 |
Slack_email_addresses = {
|
22 |
'Rahul Mandowara': '[email protected]',
|
23 |
+
'Abhimanyu Malik':'[email protected]',
|
24 |
+
'Viky Sangoi': '[email protected]',
|
25 |
+
'Ninad Mandavkar': '[email protected]',
|
26 |
'Priyanshi Nahata': '[email protected]',
|
27 |
+
'Kiran Jadhav': '[email protected]',
|
28 |
'Bhavin Parmar': '[email protected]',
|
29 |
+
'Rasika Jadhav': '[email protected]',
|
30 |
'Roshani Mohan': '[email protected]',
|
31 |
+
'Omkar Pawar': '[email protected]',
|
32 |
'Abhilash Sawant': '[email protected]',
|
33 |
'Hemant Yadav': '[email protected]',
|
34 |
+
'Sandeep Salunkhe': '[email protected]',
|
35 |
+
'Siddhesh Mayekar': '[email protected]',
|
36 |
+
'Chetan Patole': '[email protected]',
|
37 |
'Shweta Kanungo': '[email protected]',
|
38 |
+
'Chandni Chaurasia': '[email protected]',
|
39 |
+
'Rasika Salunkhe': '[email protected]',
|
40 |
'Bhushan Khapare': '[email protected]',
|
41 |
'Vaibhavi':'[email protected]',
|
42 |
'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
|
|
|
48 |
gmail_addresses = {
|
49 |
'Rahul Mandowara': '[email protected]',
|
50 |
'Abhimanyu':'[email protected]',
|
51 |
+
'Viky Sangoi': '[email protected]',
|
52 |
+
'Ninad Mandavkar': '[email protected]',
|
53 |
+
'Omkar Pawar': '[email protected]',
|
54 |
'Priyanshi Nahata': '[email protected]',
|
55 |
+
'Kiran Jadhav': '[email protected]',
|
56 |
'Bhavin Parmar': '[email protected]',
|
57 |
+
'Rasika Jadhav': '[email protected]',
|
58 |
'Roshani Mohan': '[email protected]',
|
59 |
'Abhilash Sawant': '[email protected]',
|
60 |
'Hemant Yadav': '[email protected]',
|
61 |
+
'Sandeeo Salunkhe': '[email protected]',
|
62 |
+
'Siddhesh Mayekar': '[email protected]',
|
63 |
+
'Chetan Patole': '[email protected]',
|
64 |
'Shweta Kanungo': '[email protected]',
|
65 |
+
'Chandni Chaurasia': '[email protected]',
|
66 |
+
'Rasika Salunkhe': '[email protected]',
|
67 |
'Bhushan Khapare': '[email protected]',
|
68 |
'Vaibhavi': '[email protected]',
|
69 |
'daily-alerts-for-unsubscribed-companies': 'daily-alerts-for-unsu-aaaanufptnpzgjtmknapgi45oq@gofynd.slack.com',
|
|
|
74 |
}
|
75 |
|
76 |
Webhook_urls = {
|
77 |
+
'Rahul Mandowara': os.getenv('Slack_Rahul'),
|
78 |
+
'Abhimanyu Malik': os.getenv('Slack_Abhimanyu'),
|
79 |
+
'Viky Sangoi': os.getenv('VS'),
|
80 |
+
'Ninad Mandavkar': os.getenv('SLACK_NINAD'),
|
81 |
+
'Priyanshi Nahata': os.getenv('Slack_Priyanshi'),
|
82 |
+
'Kiran Jadhav': os.getenv('Slack_Kiran'),
|
83 |
+
'Bhavin Parmar': os.getenv('Slack_Bhavin'),
|
84 |
+
'Rasika Jadhav': os.getenv('Slack_RJ'),
|
85 |
+
'Roshani Mohan': os.getenv('Slack_Roshani'),
|
86 |
+
'Omkar Pawar': os.getenv('Slack_omkar'),
|
87 |
+
'Abhilash Sawant': os.getenv('Slack_Abhilash'),
|
88 |
+
'Hemant Yadav': os.getenv('Slack_Hemant'),
|
89 |
+
'Sandeep Salunkhe': os.getenv('Slack_Sandeep'),
|
90 |
+
'Siddhesh Mayekar': os.getenv('Slack_Sid'),
|
91 |
+
'Chetan Patole': os.getenv('Slack_Chetan'),
|
92 |
+
'Shweta Kanungo': os.getenv('Slack_Shweta'),
|
93 |
+
'Chandni Chaurasia': os.getenv('Slack_Chandni'),
|
94 |
+
'Rasika Salunkhe': os.getenv('Slack_Rasika'),
|
95 |
+
'Bhushan Khapare': os.getenv('Slack_Bhushan'),
|
96 |
+
'Vaibhavi': os.getenv('Slack_Vaibhavi'),
|
97 |
+
'daily-alerts-for-unsubscribed-companies': os.getenv('Slack_daily_alerts'),
|
98 |
+
'finance_team_internal': os.getenv('Slack_finance'),
|
99 |
+
'valyx-fynd-poc': os.getenv('valyx_poc'),
|
100 |
+
'valyx_auto_invoices': os.getenv('slack_valyx_auto')
|
101 |
}
|
102 |
|
103 |
# Define your email server details
|
app.py
CHANGED
@@ -6,6 +6,30 @@ from email.mime.multipart import MIMEMultipart
|
|
6 |
import gspread
|
7 |
from oauth2client.service_account import ServiceAccountCredentials
|
8 |
from streamlit_option_menu import option_menu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Define your email server details
|
11 |
EMAIL_HOST = 'smtp.gmail.com'
|
@@ -279,7 +303,7 @@ if selected_option == "External users":
|
|
279 |
subject = row['Subject']
|
280 |
message = row['Message']
|
281 |
cc_addresses = row['CC Addresses'].split(',') if 'CC Addresses' in row else []
|
282 |
-
Folder_IDs = row['Folder IDs']
|
283 |
# company_name = row['Company_Name']
|
284 |
# company_id = row['Company_ID']
|
285 |
|
@@ -292,16 +316,61 @@ if selected_option == "External users":
|
|
292 |
if cc_addresses:
|
293 |
msg['Cc'] = ','.join(cc_addresses)
|
294 |
|
295 |
-
body = f"
|
296 |
msg.attach(MIMEText(body, 'plain'))
|
297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
try:
|
299 |
-
# Send the email
|
300 |
with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
|
301 |
server.starttls()
|
302 |
server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
|
303 |
-
server.
|
304 |
-
|
305 |
except Exception as e:
|
306 |
st.error(f"Failed to send email to {email}: {str(e)}")
|
307 |
|
|
|
6 |
import gspread
|
7 |
from oauth2client.service_account import ServiceAccountCredentials
|
8 |
from streamlit_option_menu import option_menu
|
9 |
+
from io import BytesIO
|
10 |
+
import requests
|
11 |
+
from email.mime.application import MIMEApplication
|
12 |
+
import os
|
13 |
+
|
14 |
+
# Function to read files from local path
|
15 |
+
def read_file(path):
|
16 |
+
try:
|
17 |
+
with open(path, 'rb') as file:
|
18 |
+
return file.read()
|
19 |
+
except Exception as e:
|
20 |
+
st.error(f"Failed to read file from {path}: {str(e)}")
|
21 |
+
return None
|
22 |
+
|
23 |
+
# Function to get file content type based on file extension
|
24 |
+
def get_content_type(file_path):
|
25 |
+
if file_path.lower().endswith('.pdf'):
|
26 |
+
return 'application/pdf'
|
27 |
+
elif file_path.lower().endswith('.csv'):
|
28 |
+
return 'text/csv'
|
29 |
+
elif file_path.lower().endswith('.xlsx'):
|
30 |
+
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
31 |
+
else:
|
32 |
+
return 'application/octet-stream'
|
33 |
|
34 |
# Define your email server details
|
35 |
EMAIL_HOST = 'smtp.gmail.com'
|
|
|
303 |
subject = row['Subject']
|
304 |
message = row['Message']
|
305 |
cc_addresses = row['CC Addresses'].split(',') if 'CC Addresses' in row else []
|
306 |
+
Folder_IDs = row['Folder IDs'].split(',')
|
307 |
# company_name = row['Company_Name']
|
308 |
# company_id = row['Company_ID']
|
309 |
|
|
|
316 |
if cc_addresses:
|
317 |
msg['Cc'] = ','.join(cc_addresses)
|
318 |
|
319 |
+
body = f"""{message}"""
|
320 |
msg.attach(MIMEText(body, 'plain'))
|
321 |
|
322 |
+
|
323 |
+
# Read and attach PDFs
|
324 |
+
for folder_id in Folder_IDs:
|
325 |
+
pdf_path = folder_id.strip()
|
326 |
+
if pdf_path.endswith('.pdf'):
|
327 |
+
pdf_content = read_file(pdf_path)
|
328 |
+
if pdf_content:
|
329 |
+
part = MIMEApplication(pdf_content, Name=os.path.basename(pdf_path))
|
330 |
+
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(pdf_path)}"'
|
331 |
+
msg.attach(part)
|
332 |
+
|
333 |
+
|
334 |
+
# Read and attach CSV files
|
335 |
+
for folder_id in Folder_IDs:
|
336 |
+
csv_path = folder_id.strip()
|
337 |
+
if csv_path.endswith('.csv'):
|
338 |
+
csv_content = read_file(csv_path)
|
339 |
+
if csv_content:
|
340 |
+
part = MIMEApplication(csv_content, Name=os.path.basename(csv_path))
|
341 |
+
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(csv_path)}"'
|
342 |
+
msg.attach(part)
|
343 |
+
|
344 |
+
# Read and attach XLSX files
|
345 |
+
for folder_id in Folder_IDs:
|
346 |
+
xlsx_path = folder_id.strip()
|
347 |
+
if xlsx_path.endswith('.xlsx'):
|
348 |
+
xlsx_content = read_file(xlsx_path)
|
349 |
+
if xlsx_content:
|
350 |
+
part = MIMEApplication(xlsx_content, Name=os.path.basename(xlsx_path))
|
351 |
+
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(xlsx_path)}"'
|
352 |
+
msg.attach(part)
|
353 |
+
|
354 |
+
|
355 |
+
|
356 |
+
# Read and attach ZIP files
|
357 |
+
for folder_id in Folder_IDs:
|
358 |
+
zip_path = folder_id.strip()
|
359 |
+
if zip_path.endswith('.zip'):
|
360 |
+
zip_content = read_file(zip_path)
|
361 |
+
if zip_content:
|
362 |
+
part = MIMEApplication(zip_content, Name=os.path.basename(zip_path))
|
363 |
+
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(zip_path)}"'
|
364 |
+
msg.attach(part)
|
365 |
+
|
366 |
+
|
367 |
+
# Send the email
|
368 |
try:
|
|
|
369 |
with smtplib.SMTP(EMAIL_HOST, EMAIL_PORT) as server:
|
370 |
server.starttls()
|
371 |
server.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
|
372 |
+
server.sendmail(msg['From'], [email] + cc_addresses, msg.as_string())
|
373 |
+
st.success(f"Email sent to {email}")
|
374 |
except Exception as e:
|
375 |
st.error(f"Failed to send email to {email}: {str(e)}")
|
376 |
|