AIEmailAutomationUtility 0.0.14__py3-none-any.whl → 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- AIEmailAutomationUtility/EmailReplyAssistant.py +8 -8
- AIEmailAutomationUtility/Email_Classification.py +20 -20
- AIEmailAutomationUtility/Email_DocumentUploader.py +6 -6
- AIEmailAutomationUtility/Email_Draft.py +20 -20
- AIEmailAutomationUtility/Email_Read.py +42 -42
- {AIEmailAutomationUtility-0.0.14.dist-info → AIEmailAutomationUtility-0.0.16.dist-info}/METADATA +1 -1
- AIEmailAutomationUtility-0.0.16.dist-info/RECORD +14 -0
- AIEmailAutomationUtility-0.0.14.dist-info/RECORD +0 -14
- {AIEmailAutomationUtility-0.0.14.dist-info → AIEmailAutomationUtility-0.0.16.dist-info}/LICENCE.txt +0 -0
- {AIEmailAutomationUtility-0.0.14.dist-info → AIEmailAutomationUtility-0.0.16.dist-info}/WHEEL +0 -0
- {AIEmailAutomationUtility-0.0.14.dist-info → AIEmailAutomationUtility-0.0.16.dist-info}/top_level.txt +0 -0
@@ -19,23 +19,23 @@ class EmailReplyAssistant:
|
|
19
19
|
|
20
20
|
def on_text_created(self, text):
|
21
21
|
if isinstance(text, str):
|
22
|
-
|
22
|
+
logger.log(f"\nAssistant: {text}")
|
23
23
|
|
24
24
|
def on_text_delta(self, delta, snapshot):
|
25
25
|
self.delta_values.append(delta.value)
|
26
26
|
|
27
27
|
def on_tool_call_created(self, tool_call):
|
28
|
-
|
28
|
+
logger.log(f"\nAssistant: {tool_call.type}\n")
|
29
29
|
|
30
30
|
def on_tool_call_delta(self, delta, snapshot):
|
31
31
|
if delta.type == 'code_interpreter':
|
32
32
|
if delta.code_interpreter.input:
|
33
|
-
|
33
|
+
logger.log(delta.code_interpreter.input)
|
34
34
|
if delta.code_interpreter.outputs:
|
35
|
-
|
35
|
+
logger.log(f"\n\nOutput >", flush=True)
|
36
36
|
for output in delta.code_interpreter.outputs:
|
37
37
|
if output.type == "logs":
|
38
|
-
|
38
|
+
logger.log(output.logs, flush=True)
|
39
39
|
|
40
40
|
openAI_response = ""
|
41
41
|
client = OpenAI(api_key=openAI_key)
|
@@ -66,7 +66,7 @@ class EmailReplyAssistant:
|
|
66
66
|
except Exception as error:
|
67
67
|
responseStr = "<br/><br/>" + str(error)
|
68
68
|
trace = traceback.format_exc()
|
69
|
-
|
69
|
+
logger.log(f"Exception in process_Email: {responseStr} \n {trace} \n DataType ::: {type(responseStr)}")
|
70
70
|
m = re.search(r"({.*})", str(error))
|
71
71
|
data = ast.literal_eval(m.group(1)).get('error') if m else {}
|
72
72
|
return {"status": "Failed", "message": data.get('message')}
|
@@ -88,8 +88,8 @@ class EmailReplyAssistant:
|
|
88
88
|
subject=subject
|
89
89
|
)
|
90
90
|
|
91
|
-
#
|
91
|
+
# logger.log(f"Reply_Email_Ai_Assistant response: {email_response}")
|
92
92
|
return email_response
|
93
93
|
|
94
94
|
except Exception as e:
|
95
|
-
|
95
|
+
logger.log(f"Error in Read_Email: {str(e)}")
|
@@ -27,14 +27,14 @@ class Email_Classification:
|
|
27
27
|
presence_penalty=0,
|
28
28
|
)
|
29
29
|
category = json.loads(result.choices[0].message.content.replace("\n```", "").replace("```", "").replace("json","").replace("JSON","").replace("csv","").replace("CSV",""))['category']
|
30
|
-
|
30
|
+
logger.log(f"category:: {category}")
|
31
31
|
return {"status": "Success", "message": category}
|
32
32
|
except Exception as e:
|
33
|
-
|
33
|
+
logger.log(f"Error detecting category with OpenAI: {str(e)}")
|
34
34
|
return {"success": "Failed", "message": f"Error detecting category with OpenAI: {str(e)}"}
|
35
35
|
|
36
36
|
def detect_category_gemini(self, gemini_api_key, categories, email_body, detect_email_category=True, signature=None):
|
37
|
-
|
37
|
+
logger.log("Inside detect_category_gemini::")
|
38
38
|
try:
|
39
39
|
categories_str = ', '.join(categories)
|
40
40
|
if detect_email_category:
|
@@ -48,7 +48,7 @@ class Email_Classification:
|
|
48
48
|
"content": f"Create a reply for the email received from a customer. Include the email signature as {signature}\nDo not include any instruction as the output will be directly in a program."
|
49
49
|
}]
|
50
50
|
|
51
|
-
|
51
|
+
logger.log(f"Final Gemini AI message for detecting category::: {message}")
|
52
52
|
message_list = str(message)
|
53
53
|
|
54
54
|
generation_config = {
|
@@ -62,8 +62,8 @@ class Email_Classification:
|
|
62
62
|
model = genai.GenerativeModel('gemini-1.0-pro')
|
63
63
|
response = model.generate_content(message_list)
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
logger.log(f"Input Question ::: {email_body}\ngemini-1.0-pro Response::: {response} {type(response)}")
|
66
|
+
logger.log(f"\n\nResponse GeminiAI endpoint::::: {response} \n{type(response)}", "0")
|
67
67
|
|
68
68
|
final_result = ""
|
69
69
|
for part in response:
|
@@ -74,23 +74,23 @@ class Email_Classification:
|
|
74
74
|
if final_result.startswith("{{") and final_result.endswith("}}"):
|
75
75
|
final_result = final_result[1:-1]
|
76
76
|
final_result = json.loads(final_result)
|
77
|
-
|
77
|
+
logger.log(f"finalResult::: {final_result}")
|
78
78
|
except json.JSONDecodeError:
|
79
|
-
|
79
|
+
logger.log(f"Exception : Invalid JSON Response GEMINI 1.5: {final_result} {type(final_result)}")
|
80
80
|
|
81
81
|
if detect_email_category:
|
82
82
|
category = final_result.get('category', 'Others')
|
83
83
|
return {"status": "Success", "message": category}
|
84
84
|
else:
|
85
|
-
|
85
|
+
logger.log(f"finalResult::: {final_result}")
|
86
86
|
return {"status": "Success", "message": final_result}
|
87
87
|
|
88
88
|
except Exception as e:
|
89
|
-
|
89
|
+
logger.log(f"Error with Gemini AI detection/generation: {str(e)}")
|
90
90
|
return {"success": "Failed", "message": f"Error with Gemini AI detection/generation: {str(e)}"}
|
91
91
|
|
92
92
|
def detect_category_local(self, openai_api_key, categories, email_body, detect_email_category=True, signature=None, local_ai_url=None):
|
93
|
-
|
93
|
+
logger.log("Inside detect_category_local::")
|
94
94
|
try:
|
95
95
|
categories_str = ', '.join(categories)
|
96
96
|
if detect_email_category:
|
@@ -104,7 +104,7 @@ class Email_Classification:
|
|
104
104
|
"content": f"Create a reply for the email received from a customer. Include the email signature as {signature}\nDo not include any instruction as the output will be directly in a program."
|
105
105
|
}]
|
106
106
|
|
107
|
-
|
107
|
+
logger.log(f"Final Local AI message for detecting category::: {message}")
|
108
108
|
openai.api_key = openai_api_key
|
109
109
|
client = OpenAI(base_url=local_ai_url, api_key="lm-studio")
|
110
110
|
completion = client.chat.completions.create(
|
@@ -116,7 +116,7 @@ class Email_Classification:
|
|
116
116
|
)
|
117
117
|
|
118
118
|
final_result = str(completion.choices[0].message.content)
|
119
|
-
|
119
|
+
logger.log(f"\n\nInput Question ::: {email_body}\nLocalAI endpoint finalResult ::::: {final_result} \n{type(final_result)}", "0")
|
120
120
|
|
121
121
|
if detect_email_category:
|
122
122
|
try:
|
@@ -125,21 +125,21 @@ class Email_Classification:
|
|
125
125
|
if json_start != -1 and json_end != -1:
|
126
126
|
json_str = final_result[json_start:json_end]
|
127
127
|
final_result = json.loads(json_str)
|
128
|
-
|
128
|
+
logger.log(f"finalResult::: {final_result}")
|
129
129
|
category = final_result.get('category', 'Others')
|
130
|
-
|
130
|
+
logger.log(f"category::1037 {category}")
|
131
131
|
return {"status": "Success", "message": category}
|
132
132
|
else:
|
133
133
|
raise ValueError("No valid JSON object found in the response")
|
134
134
|
except json.JSONDecodeError as e:
|
135
|
-
|
135
|
+
logger.log(f"JSON decode error: {e}")
|
136
136
|
raise
|
137
137
|
else:
|
138
|
-
|
138
|
+
logger.log(f"finalResult:1040 {final_result}")
|
139
139
|
return {"status": "Success", "message": final_result}
|
140
140
|
|
141
141
|
except Exception as e:
|
142
|
-
|
142
|
+
logger.log(f"Error with LocalAI detection/generation: {str(e)}")
|
143
143
|
return {"success": "Failed", "message": f"Error with LocalAI detection/generation: {str(e)}"}
|
144
144
|
|
145
145
|
def detect_category(self, data):
|
@@ -180,9 +180,9 @@ class Email_Classification:
|
|
180
180
|
else:
|
181
181
|
return {"status": "Failed", "message": f"Invalid model_type: {model_type}"}
|
182
182
|
|
183
|
-
|
183
|
+
logger.log(f"Detect_Category response: {response}")
|
184
184
|
return response
|
185
185
|
|
186
186
|
except Exception as e:
|
187
|
-
|
187
|
+
logger.log(f"Error in Detect_Category: {str(e)}")
|
188
188
|
return e
|
@@ -8,7 +8,7 @@ from flask import Flask,request
|
|
8
8
|
class Email_DocumentUploader:
|
9
9
|
def upload_document(self, upload_config, file_data):
|
10
10
|
# try:
|
11
|
-
|
11
|
+
logger.log("inside function" )
|
12
12
|
# Create temp directory if needed
|
13
13
|
temp_dir = "temp"
|
14
14
|
if not os.path.exists(temp_dir):
|
@@ -16,7 +16,7 @@ class Email_DocumentUploader:
|
|
16
16
|
|
17
17
|
# Save file temporarily
|
18
18
|
file_path = os.path.join(temp_dir, file_data['filename'])
|
19
|
-
|
19
|
+
logger.log(f"file_path:: {file_path}")
|
20
20
|
with open(file_path, 'wb') as f:
|
21
21
|
f.write(file_data['content'])
|
22
22
|
|
@@ -30,7 +30,7 @@ class Email_DocumentUploader:
|
|
30
30
|
"FILE_TYPE": "file_type",
|
31
31
|
"APP_ID": "app_id"
|
32
32
|
}
|
33
|
-
|
33
|
+
logger.log(f"param_fields:: {param_fields}")
|
34
34
|
|
35
35
|
for api_key, config_key in param_fields.items():
|
36
36
|
if config_key in upload_config and upload_config[config_key]:
|
@@ -46,7 +46,7 @@ class Email_DocumentUploader:
|
|
46
46
|
files=files,
|
47
47
|
data=params
|
48
48
|
)
|
49
|
-
|
49
|
+
logger.log("file read")
|
50
50
|
|
51
51
|
if response.status_code == 200:
|
52
52
|
result = json.loads(response.text)
|
@@ -56,7 +56,7 @@ class Email_DocumentUploader:
|
|
56
56
|
return str(response.status_code), f"Upload failed: {response.text}"
|
57
57
|
|
58
58
|
def email_document_upload(self, file, parameters_details):
|
59
|
-
|
59
|
+
logger.log(f"file ::: {file}")
|
60
60
|
if not file:
|
61
61
|
return "file not found"
|
62
62
|
|
@@ -81,5 +81,5 @@ class Email_DocumentUploader:
|
|
81
81
|
|
82
82
|
response_status, restAPI_Result = self.upload_document(upload_config, file_data)
|
83
83
|
|
84
|
-
|
84
|
+
logger.log(f"Upload_Document response result: {restAPI_Result}")
|
85
85
|
return response_status, restAPI_Result
|
@@ -27,22 +27,22 @@ class Email_Draft:
|
|
27
27
|
message.set_payload(f"{response_content}\n\n{mail_details}\n\n{email_details['body']}")
|
28
28
|
|
29
29
|
utf8_message = str(message).encode("utf-8")
|
30
|
-
#
|
30
|
+
# logger.log(f"utf8_message:: {utf8_message}")
|
31
31
|
imap_ssl.append("[Gmail]/Drafts", '', imaplib.Time2Internaldate(time.time()), utf8_message)
|
32
32
|
|
33
33
|
return True, utf8_message.decode("utf-8")
|
34
34
|
|
35
35
|
except Exception as e:
|
36
|
-
|
36
|
+
logger.log(f"Error creating draft: {str(e)}")
|
37
37
|
|
38
38
|
def draft_email_response(self, email_details):
|
39
39
|
try:
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
logger.log("Creating draft email with the following details:")
|
41
|
+
logger.log(f"From: {email_details.get('from')}")
|
42
|
+
logger.log(f"To: {email_details.get('to')}")
|
43
|
+
logger.log(f"CC: {email_details.get('cc')}")
|
44
|
+
logger.log(f"Subject: {email_details.get('subject')}")
|
45
|
+
logger.log(f"Body: {email_details.get('body')}")
|
46
46
|
|
47
47
|
return "Success", {
|
48
48
|
"from": email_details['from'],
|
@@ -53,7 +53,7 @@ class Email_Draft:
|
|
53
53
|
}
|
54
54
|
|
55
55
|
except Exception as e:
|
56
|
-
|
56
|
+
logger.log(f"Error creating draft: {str(e)}")
|
57
57
|
return "Failed", None
|
58
58
|
|
59
59
|
def draft_mail(self, data):
|
@@ -61,35 +61,35 @@ class Email_Draft:
|
|
61
61
|
|
62
62
|
if "reciever_email_addr" in data and data["reciever_email_addr"] != None:
|
63
63
|
reciever_email_addr = data["reciever_email_addr"]
|
64
|
-
|
64
|
+
logger.log(f"\nInside reciever_email_addr value:::\t{reciever_email_addr} \t{type(reciever_email_addr)}","0")
|
65
65
|
|
66
66
|
if "receiver_email_pwd" in data and data["receiver_email_pwd"] != None:
|
67
67
|
receiver_email_pwd = data["receiver_email_pwd"]
|
68
|
-
|
68
|
+
logger.log(f"\nInside receiver_email_pwd value:::\t{receiver_email_pwd} \t{type(receiver_email_pwd)}","0")
|
69
69
|
|
70
70
|
if "host_name" in data and data["host_name"] != None:
|
71
71
|
host_name = data["host_name"]
|
72
|
-
|
72
|
+
logger.log(f"\nInside host_name value:::\t{host_name} \t{type(host_name)}","0")
|
73
73
|
|
74
74
|
if "sender_email_addr" in data and data["sender_email_addr"] != None:
|
75
75
|
sender_email_addr = data["sender_email_addr"]
|
76
|
-
|
76
|
+
logger.log(f"\nInside sender_email_addr value:::\t{sender_email_addr} \t{type(sender_email_addr)}","0")
|
77
77
|
|
78
78
|
if "cc_email_addr" in data and data["cc_email_addr"] != None:
|
79
79
|
cc_email_addr = data["cc_email_addr"]
|
80
|
-
|
80
|
+
logger.log(f"\nInside cc_email_addr value:::\t{cc_email_addr} \t{type(cc_email_addr)}","0")
|
81
81
|
|
82
82
|
if "subject" in data and data["subject"] != None:
|
83
83
|
subject = data["subject"]
|
84
|
-
|
84
|
+
logger.log(f"\nInside subject value:::\t{subject} \t{type(subject)}","0")
|
85
85
|
|
86
86
|
if "email_body" in data and data["email_body"] != None:
|
87
87
|
email_body = data["email_body"]
|
88
|
-
|
88
|
+
logger.log(f"\nInside email_body value:::\t{email_body} \t{type(email_body)}","0")
|
89
89
|
|
90
90
|
if "signature" in data and data["signature"] != None:
|
91
91
|
signature = data["signature"]
|
92
|
-
|
92
|
+
logger.log(f"\nInside signature value:::\t{signature} \t{type(signature)}","0")
|
93
93
|
|
94
94
|
|
95
95
|
email_config = {
|
@@ -97,7 +97,7 @@ class Email_Draft:
|
|
97
97
|
"password": data["receiver_email_pwd"],
|
98
98
|
"host": data["host_name"]
|
99
99
|
}
|
100
|
-
|
100
|
+
logger.log(f"data::{data}")
|
101
101
|
email_details = {
|
102
102
|
"from": data["sender_email_addr"],
|
103
103
|
"to":data["reciever_email_addr"],
|
@@ -110,8 +110,8 @@ class Email_Draft:
|
|
110
110
|
success, draft_message = self.draft_email_response(email_details)
|
111
111
|
|
112
112
|
if success == "Success":
|
113
|
-
|
113
|
+
logger.log(f"draft_message {draft_message}")
|
114
114
|
return draft_message
|
115
115
|
|
116
116
|
except Exception as e:
|
117
|
-
|
117
|
+
logger.log(f"Error in Draft_Save: {str(e)}")
|
@@ -18,10 +18,10 @@ from .Email_DocumentUploader import Email_DocumentUploader
|
|
18
18
|
class Email_Read:
|
19
19
|
def read_email(self, email_config):
|
20
20
|
try:
|
21
|
-
|
21
|
+
logger.log("inside read_email")
|
22
22
|
mail = imaplib.IMAP4_SSL(email_config['host'], email_config['port'])
|
23
23
|
mail.login(email_config['email'], email_config['password'])
|
24
|
-
|
24
|
+
logger.log("login successfully")
|
25
25
|
mail.select('inbox')
|
26
26
|
|
27
27
|
while True:
|
@@ -32,8 +32,8 @@ class Email_Read:
|
|
32
32
|
email_ids = email_ids[0].split()
|
33
33
|
|
34
34
|
if not email_ids:
|
35
|
-
|
36
|
-
|
35
|
+
logger.log("Email not found, going to check new mail")
|
36
|
+
logger.log("Email not found,\ngoing to check new mail \n")
|
37
37
|
else:
|
38
38
|
|
39
39
|
for email_id in email_ids:
|
@@ -67,10 +67,10 @@ class Email_Read:
|
|
67
67
|
"body": email_body
|
68
68
|
}
|
69
69
|
emails.append(email_data)
|
70
|
-
|
70
|
+
logger.log(f"emails:: {emails}")
|
71
71
|
call_save_transaction = Save_Transaction()
|
72
72
|
save_transaction_response = call_save_transaction.email_save_transaction(email_data)
|
73
|
-
|
73
|
+
logger.log(f"save_transaction_response:: {save_transaction_response}")
|
74
74
|
time.sleep(10)
|
75
75
|
|
76
76
|
except Exception as e:
|
@@ -80,12 +80,12 @@ class Email_Read:
|
|
80
80
|
mail.close()
|
81
81
|
mail.logout()
|
82
82
|
except Exception as close_error:
|
83
|
-
|
83
|
+
logger.log(f"Error during mail close/logout: {str(close_error)}")
|
84
84
|
|
85
85
|
def read_email_automation(self, email_config):
|
86
86
|
# try:
|
87
|
-
|
88
|
-
#
|
87
|
+
logger.log(f"inside read_email_automation")
|
88
|
+
# logger.log(f"email_config ::: {email_config}")
|
89
89
|
LABEL = "Unprocessed_Email"
|
90
90
|
file_JsonArray = []
|
91
91
|
templateName = "ai_email_automation.json"
|
@@ -99,7 +99,7 @@ class Email_Read:
|
|
99
99
|
|
100
100
|
mail = imaplib.IMAP4_SSL(host, port)
|
101
101
|
mail.login(reciever_email_addr, receiver_email_pwd)
|
102
|
-
|
102
|
+
logger.log("login successfully")
|
103
103
|
mail.select('inbox')
|
104
104
|
|
105
105
|
file_JsonArray, categories = self.read_JSON_File(templateName)
|
@@ -112,8 +112,8 @@ class Email_Read:
|
|
112
112
|
email_ids = email_ids[0].split()
|
113
113
|
|
114
114
|
if not email_ids:
|
115
|
-
|
116
|
-
|
115
|
+
logger.log("Email not found, going to check new mail")
|
116
|
+
logger.log("Email not found,\ngoing to check new mail \n")
|
117
117
|
else:
|
118
118
|
|
119
119
|
for email_id in email_ids:
|
@@ -140,8 +140,8 @@ class Email_Read:
|
|
140
140
|
email_body = msg.get_payload(decode=True).decode('utf-8', errors='replace')
|
141
141
|
|
142
142
|
openai_Process_Input = email_body
|
143
|
-
|
144
|
-
|
143
|
+
logger.log(f"\nEmail Subject::: {subject}")
|
144
|
+
logger.log(f"\nEmail body::: {openai_Process_Input}")
|
145
145
|
|
146
146
|
openai_api_key = email_config.get('openai_api_key', '')
|
147
147
|
geminiAI_APIKey = email_config.get('gemini_api_key', '')
|
@@ -158,21 +158,21 @@ class Email_Read:
|
|
158
158
|
"signature" : signature,
|
159
159
|
"local_ai_url" : localAIURL,
|
160
160
|
}
|
161
|
-
#
|
161
|
+
# logger.log(f"\nemail_cat_data ::: {email_cat_data}")
|
162
162
|
email_classification = Email_Classification()
|
163
163
|
emailCategory = email_classification.detect_category(email_cat_data)
|
164
164
|
emailCategory = emailCategory['message']
|
165
|
-
|
165
|
+
logger.log(f"\nDetected Email category ::: {emailCategory}")
|
166
166
|
|
167
167
|
if emailCategory == 'Others':
|
168
|
-
|
168
|
+
logger.log(f"Marking email as UNREAD. ")
|
169
169
|
mail.store(email_id, '-FLAGS', '\\Seen')
|
170
170
|
|
171
171
|
mail.create(LABEL)
|
172
172
|
mail.copy(email_id, LABEL)
|
173
173
|
mail.store(email_id, '+FLAGS', '\\Deleted') # Mark for deletion
|
174
174
|
mail.expunge()
|
175
|
-
|
175
|
+
logger.log(f"Mail removed from inbox and added to '{LABEL}' label.")
|
176
176
|
|
177
177
|
elif emailCategory == "Product Enquiry":
|
178
178
|
|
@@ -188,30 +188,30 @@ class Email_Read:
|
|
188
188
|
|
189
189
|
email_draft = Email_Draft()
|
190
190
|
status, response = email_draft.draft_email(email_config, email_details, openai_Response['message'])
|
191
|
-
|
191
|
+
logger.log(f"status ::: {status}")
|
192
192
|
else :
|
193
193
|
message = f"Invalid response method received '{responseMethod}' for category : '{emailCategory}'"
|
194
194
|
raise ValueError(message)
|
195
195
|
elif Model_Name == "LocalAI":
|
196
|
-
|
196
|
+
logger.log("localAI")
|
197
197
|
Detect_Email_category = False
|
198
198
|
LocalAI_Response = emailCategory
|
199
|
-
|
199
|
+
logger.log(f"Process LocalAI_Response ::: {LocalAI_Response}\n")
|
200
200
|
email_details = {"sender":sender_email_addr, "cc":cc_email_addr, "subject":subject, "body": email_body}
|
201
201
|
|
202
202
|
email_draft = Email_Draft()
|
203
203
|
status, response = email_draft.draft_email(email_config, email_details, LocalAI_Response)
|
204
|
-
|
204
|
+
logger.log(f"status ::: {status}")
|
205
205
|
elif Model_Name == "GeminiAI":
|
206
|
-
|
206
|
+
logger.log("GeminiAI")
|
207
207
|
Detect_Email_category = False
|
208
208
|
GeminiAI_Response = emailCategory
|
209
|
-
|
209
|
+
logger.log(f"Process GeminiAI_Response ::: {GeminiAI_Response}\n")
|
210
210
|
email_details = {"sender":sender_email_addr, "cc":cc_email_addr, "subject":subject, "body": email_body}
|
211
211
|
|
212
212
|
email_draft = Email_Draft()
|
213
213
|
status, response = email_draft.draft_email(email_config, email_details, GeminiAI_Response)
|
214
|
-
|
214
|
+
logger.log(f"status ::: {status}")
|
215
215
|
else:
|
216
216
|
raise ValueError(f"Invalid Model Name provided : '{Model_Name}'")
|
217
217
|
|
@@ -226,18 +226,18 @@ class Email_Read:
|
|
226
226
|
email_upload_document = Email_DocumentUploader()
|
227
227
|
with open(f"temp/{fileName}", "rb") as file:
|
228
228
|
response_status, restAPI_Result = email_upload_document.email_document_upload(file, parameters)
|
229
|
-
|
229
|
+
logger.log(f"email_upload_document_response ::: {restAPI_Result}")
|
230
230
|
else:
|
231
231
|
|
232
232
|
new_fileName = self.create_file_from_emailBody(email_body, sender_email_addr, parameters)
|
233
233
|
with open(f"temp/{new_fileName}", "rb") as file:
|
234
234
|
response_status, restAPI_Result = email_upload_document.email_document_upload(file, parameters)
|
235
|
-
|
235
|
+
logger.log(f"email_upload_document_response ::: {restAPI_Result}")
|
236
236
|
|
237
237
|
if response_status == "200" :
|
238
|
-
|
238
|
+
logger.log(f"Attachment uploaded sucessfully against Document id: '{restAPI_Result}'.")
|
239
239
|
else:
|
240
|
-
|
240
|
+
logger.log(restAPI_Result)
|
241
241
|
|
242
242
|
else :
|
243
243
|
message = f"Invalid response method received '{responseMethod}' for category : '{emailCategory}'"
|
@@ -254,7 +254,7 @@ class Email_Read:
|
|
254
254
|
# mail.close()
|
255
255
|
# mail.logout()
|
256
256
|
# except Exception as close_error:
|
257
|
-
#
|
257
|
+
# logger.log(f"Error during mail close/logout: {str(close_error)}")
|
258
258
|
# return {"status": "Failed", "message": f"Error reading emails: {str(close_error)}"}
|
259
259
|
|
260
260
|
def save_attachment(self, part, download_dir):
|
@@ -269,7 +269,7 @@ class Email_Read:
|
|
269
269
|
with open(file_path, 'wb') as f:
|
270
270
|
f.write(part.get_payload(decode=True))
|
271
271
|
|
272
|
-
|
272
|
+
logger.log(f"Attachment saved: {file_path}")
|
273
273
|
return file_path
|
274
274
|
except Exception as e:
|
275
275
|
return {"success": "Failed", "message": f"Error saving attachment: {str(e)}"}
|
@@ -288,10 +288,10 @@ class Email_Read:
|
|
288
288
|
if not all([reciever_email_addr, receiver_email_pwd, host, port]):
|
289
289
|
raise ValueError("Missing required email configuration fields.")
|
290
290
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
291
|
+
logger.log(f"\nReceiver Email Address: {reciever_email_addr}\t{type(reciever_email_addr)}", "0")
|
292
|
+
logger.log(f"\nReceiver Email Password: {receiver_email_pwd}\t{type(receiver_email_pwd)}", "0")
|
293
|
+
logger.log(f"\nHost: {host}\t{type(host)}", "0")
|
294
|
+
logger.log(f"\nPort: {port}\t{type(port)}", "0")
|
295
295
|
|
296
296
|
email_config = {
|
297
297
|
'email': reciever_email_addr,
|
@@ -304,10 +304,10 @@ class Email_Read:
|
|
304
304
|
}
|
305
305
|
|
306
306
|
emails = self.read_email(email_config)
|
307
|
-
|
307
|
+
logger.log(f"Read_Email response: {emails}")
|
308
308
|
|
309
309
|
except Exception as e:
|
310
|
-
|
310
|
+
logger.log(f"Error in Read_Email: {str(e)}")
|
311
311
|
|
312
312
|
def download_attachment(self, msg):
|
313
313
|
filepath = ""
|
@@ -328,9 +328,9 @@ class Email_Read:
|
|
328
328
|
filepath = os.path.join(ATTACHMENT_SAVE_PATH, filename)
|
329
329
|
with open(filepath, 'wb') as f:
|
330
330
|
f.write(part.get_payload(decode=True))
|
331
|
-
|
331
|
+
logger.log(f"\nAttachment saved: '{filepath}'")
|
332
332
|
else:
|
333
|
-
|
333
|
+
logger.log("\nNo Attachment found.")
|
334
334
|
return filename
|
335
335
|
|
336
336
|
def read_JSON_File(self, json_fileName):
|
@@ -355,7 +355,7 @@ class Email_Read:
|
|
355
355
|
except Exception as e:
|
356
356
|
msg = f"'{json_fileName}' file is empty. Please provide JSON parameters in the filename."
|
357
357
|
trace = traceback.format_exc()
|
358
|
-
|
358
|
+
logger.log(f"Exception in writeJsonFile: {msg} \n {trace} \n DataType ::: {type(msg)}")
|
359
359
|
raise Exception(msg)
|
360
360
|
|
361
361
|
def get_JsonArray_values(self, category, jsonArray):
|
@@ -386,7 +386,7 @@ class Email_Read:
|
|
386
386
|
pdf.set_font("Arial", size=12)
|
387
387
|
pdf.multi_cell(0, 10, text)
|
388
388
|
pdf.output(filePath)
|
389
|
-
|
389
|
+
logger.log(f"New PDF file created from email body and stored in '{filePath}'")
|
390
390
|
|
391
391
|
elif parameters["FILE_TYPE"] == "txt":
|
392
392
|
fileName = fileName + ".txt"
|
@@ -394,7 +394,7 @@ class Email_Read:
|
|
394
394
|
|
395
395
|
with open(filePath, "w") as file:
|
396
396
|
file.write(text)
|
397
|
-
|
397
|
+
logger.log(f"New TXT file created from email body and stored in '{filePath}'")
|
398
398
|
else:
|
399
399
|
message = f"Invalid File Type received. "
|
400
400
|
self.send_response(200)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
AIEmailAutomationUtility/EmailReplyAssistant.py,sha256=AK2I1j2wa6NvR9ysKgtQsm-wkaeKQycQdzREXR0Ptb8,3886
|
2
|
+
AIEmailAutomationUtility/Email_Classification.py,sha256=eL52Td50zo7V0QTIqjN4Khhg-5HKvf2RUITIcKz5yZ0,9343
|
3
|
+
AIEmailAutomationUtility/Email_DocumentUploader.py,sha256=ImTmMz_JeU6Xynt9kyu7lFv7vqrxzqAtBF-A7014fYc,3055
|
4
|
+
AIEmailAutomationUtility/Email_Draft.py,sha256=BfseewnnlwNl1moodq3kZiUPXDUE9a_nQjuFQsUp3fY,5244
|
5
|
+
AIEmailAutomationUtility/Email_Read.py,sha256=Wc8HzZfMkDZ6XjjfNOibrI6r5XsytPEoA1ilw4DPRuA,20792
|
6
|
+
AIEmailAutomationUtility/Email_Upload_Document.py,sha256=3bdkxfDlwoeRp-46KPw2Gs1dqBhEIoA1yE5GCudpdV8,1320
|
7
|
+
AIEmailAutomationUtility/Save_Draft.py,sha256=yzLgFN14I_lXE6qL0I3tKNduvcnWdbsY9i2mKdTtio4,5348
|
8
|
+
AIEmailAutomationUtility/Save_Transaction.py,sha256=Gg1w6hhzHmEFjsuzYvkq-3-EsWReetjLHsYSv5YIGgM,3816
|
9
|
+
AIEmailAutomationUtility/__init__.py,sha256=bB7N-qQD85RdMaXHg_ZU5oPtHtx9zgeG6-ue4rhcfYI,379
|
10
|
+
AIEmailAutomationUtility-0.0.16.dist-info/LICENCE.txt,sha256=2qX9IkEUBx0VJp1Vh9O2dsRwE-IpYId0lXDyn7OVsJ8,1073
|
11
|
+
AIEmailAutomationUtility-0.0.16.dist-info/METADATA,sha256=4p5Eaucq_pKYg3VL8qnnFREj2ewka2BgFYz6cuSUUXI,623
|
12
|
+
AIEmailAutomationUtility-0.0.16.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
13
|
+
AIEmailAutomationUtility-0.0.16.dist-info/top_level.txt,sha256=3jTWrTUblVkaP7mpwY2UBSnrlfot5Ykpfsehyke-Uzw,25
|
14
|
+
AIEmailAutomationUtility-0.0.16.dist-info/RECORD,,
|
@@ -1,14 +0,0 @@
|
|
1
|
-
AIEmailAutomationUtility/EmailReplyAssistant.py,sha256=9KYIBrgFND3NxRjlbKsaxsoCiMQMvD8WY--x73bQU04,3898
|
2
|
-
AIEmailAutomationUtility/Email_Classification.py,sha256=usZS8TeoX-bu6A6u7cWePVAxWGxuVK8etNPAwlOoruI,9243
|
3
|
-
AIEmailAutomationUtility/Email_DocumentUploader.py,sha256=zXF6PNkRjkgbe3daxbZ_XS8M1KpKKNWcmWzu-BUhxJM,3025
|
4
|
-
AIEmailAutomationUtility/Email_Draft.py,sha256=RJSoZ4tyjypjOU415YcGJYJ2Nx9uTKEPA1mCQxNH57E,5144
|
5
|
-
AIEmailAutomationUtility/Email_Read.py,sha256=E_qQ8sBvfem1OtBnaghj5t_Nc0MgdyWrZaDh8OjtJE0,20582
|
6
|
-
AIEmailAutomationUtility/Email_Upload_Document.py,sha256=3bdkxfDlwoeRp-46KPw2Gs1dqBhEIoA1yE5GCudpdV8,1320
|
7
|
-
AIEmailAutomationUtility/Save_Draft.py,sha256=yzLgFN14I_lXE6qL0I3tKNduvcnWdbsY9i2mKdTtio4,5348
|
8
|
-
AIEmailAutomationUtility/Save_Transaction.py,sha256=Gg1w6hhzHmEFjsuzYvkq-3-EsWReetjLHsYSv5YIGgM,3816
|
9
|
-
AIEmailAutomationUtility/__init__.py,sha256=bB7N-qQD85RdMaXHg_ZU5oPtHtx9zgeG6-ue4rhcfYI,379
|
10
|
-
AIEmailAutomationUtility-0.0.14.dist-info/LICENCE.txt,sha256=2qX9IkEUBx0VJp1Vh9O2dsRwE-IpYId0lXDyn7OVsJ8,1073
|
11
|
-
AIEmailAutomationUtility-0.0.14.dist-info/METADATA,sha256=jlivyoPfgZ_3VrFOn2KYZCeBFMDnVwClk1ComgVZ5BE,623
|
12
|
-
AIEmailAutomationUtility-0.0.14.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
13
|
-
AIEmailAutomationUtility-0.0.14.dist-info/top_level.txt,sha256=3jTWrTUblVkaP7mpwY2UBSnrlfot5Ykpfsehyke-Uzw,25
|
14
|
-
AIEmailAutomationUtility-0.0.14.dist-info/RECORD,,
|
{AIEmailAutomationUtility-0.0.14.dist-info → AIEmailAutomationUtility-0.0.16.dist-info}/LICENCE.txt
RENAMED
File without changes
|
{AIEmailAutomationUtility-0.0.14.dist-info → AIEmailAutomationUtility-0.0.16.dist-info}/WHEEL
RENAMED
File without changes
|
File without changes
|