Pedro Bento commited on
Commit
23b379c
·
1 Parent(s): 4d96490

added send email functionality

Browse files
Files changed (2) hide show
  1. app.py +2 -0
  2. tdagent/tools/send_email.py +84 -0
app.py CHANGED
@@ -5,6 +5,7 @@ from tdagent.tools.internal_company_user_search import gr_internal_company
5
  from tdagent.tools.letter_counter import gr_letter_counter
6
  from tdagent.tools.lookup_company_cloud_account_information import gr_lookup_company_cloud_account_information
7
  from tdagent.tools.query_abuse_ip_db import gr_query_abuseipdb
 
8
  from tdagent.tools.virus_total import gr_virus_total
9
 
10
  gr_app = gr.TabbedInterface(
@@ -15,6 +16,7 @@ gr_app = gr.TabbedInterface(
15
  gr_virus_total,
16
  gr_internal_company,
17
  gr_lookup_company_cloud_account_information,
 
18
  ],
19
  )
20
 
 
5
  from tdagent.tools.letter_counter import gr_letter_counter
6
  from tdagent.tools.lookup_company_cloud_account_information import gr_lookup_company_cloud_account_information
7
  from tdagent.tools.query_abuse_ip_db import gr_query_abuseipdb
8
+ from tdagent.tools.send_email import gr_send_email
9
  from tdagent.tools.virus_total import gr_virus_total
10
 
11
  gr_app = gr.TabbedInterface(
 
16
  gr_virus_total,
17
  gr_internal_company,
18
  gr_lookup_company_cloud_account_information,
19
+ gr_send_email,
20
  ],
21
  )
22
 
tdagent/tools/send_email.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import datetime
3
+ import random
4
+
5
+
6
+ def send_email(sender, recipient, subject, message):
7
+ """
8
+ Simulates sending an email and prints it to the console in a well-formatted way.
9
+
10
+ This function takes email details, formats them into a standard email structure
11
+ with headers and body, prints the formatted email to the console, and returns
12
+ a success message.
13
+
14
+ Parameters:
15
+ -----------
16
+ sender : str
17
+ The email address of the sender (From field)
18
+ recipient : str
19
+ The email address of the recipient (To field)
20
+ subject : str
21
+ The subject line of the email
22
+ message : str
23
+ The main body content of the email
24
+
25
+ Returns:
26
+ --------
27
+ str
28
+ A success message indicating that the email was sent, including
29
+ the recipient address and the current time
30
+
31
+ Example:
32
+ --------
33
+ >>> send_email("[email protected]", "[email protected]", "Hello", "How are you?")
34
+ ------ EMAIL SENT ------
35
36
37
+ Subject: Hello
38
+ Date: Wed, 04 Jun 2025 16:40:58 +0000
39
+ Message-ID: <123456.7890123456@mail-server>
40
+
41
+ How are you?
42
+ ------------------------
43
+ 'Email successfully sent to [email protected] at 16:40:58'
44
+
45
+ Notes:
46
+ ------
47
+ - This is a simulation function and does not actually send emails
48
+ - The Message-ID is randomly generated for each call
49
+ - The timestamp reflects the current system time
50
+ """
51
+ # Generate a random message ID
52
+ message_id = f"<{random.randint(100000, 999999)}.{random.randint(1000000000, 9999999999)}@mail-server>"
53
+
54
+ # Get current timestamp
55
+ timestamp = datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S +0000")
56
+
57
+ # Format the email
58
+ email_format = f"""
59
+ ------ EMAIL SENT ------
60
+ From: {sender}
61
+ To: {recipient}
62
+ Subject: {subject}
63
+ Date: {timestamp}
64
+ Message-ID: {message_id}
65
+
66
+ {message}
67
+ ------------------------
68
+ """
69
+
70
+ # Print the email to console
71
+ print(email_format)
72
+
73
+ # Return a success message
74
+ return f"Email successfully sent to {recipient} at {datetime.datetime.now().strftime('%H:%M:%S')}"
75
+
76
+
77
+ # Create Gradio Interface
78
+ gr_send_email = gr.Interface(
79
+ fn=send_email,
80
+ inputs=["text", "text", "text", "text"],
81
+ outputs="text",
82
+ title="Email Sender Simulator",
83
+ description="This tool simulates sending an email by formatting and printing it to the console."
84
+ )