TDAgentTools / tdagent /tools /send_email.py
pedrobento988's picture
WHOIS and fixes (#3)
0d4024a verified
import datetime
import random
import gradio as gr
def send_email(recipient: str, subject: str, message: str) -> str:
"""Simulates sending an email from [email protected].
This function takes email details, formats them into a standard email structure
with headers and body, prints the formatted email to the console, and returns
a success message. The sender is always set to [email protected].
Args:
recipient: The email address of the recipient (To field)
subject: The subject line of the email
message: The main body content of the email
Returns:
A success message indicating that the email was sent, including
the recipient address and the current time
Example:
>>> send_email("[email protected]", "Security Alert", "Please update your password.")
------ EMAIL SENT ------
From: [email protected]
To: [email protected]
Subject: Security Alert
Date: Wed, 04 Jun 2025 16:40:58 +0000
Message-ID: <123456.7890123456@mail-server>
Please update your password.
------------------------
'Email successfully sent to [email protected] at 16:40:58'
""" # noqa: E501
# Fixed sender email
sender = "[email protected]"
# Generate a random message ID
message_id = f"<{random.randint(100000, 999999)}.{random.randint(1000000000, 9999999999)}@mail-server>" # noqa: E501, S311
# Get current timestamp
timestamp = datetime.datetime.now(datetime.timezone.utc).strftime(
"%a, %d %b %Y %H:%M:%S +0000",
)
# Format the email
email_format = f"""
------ EMAIL SENT ------
From: {sender}
To: {recipient}
Subject: {subject}
Date: {timestamp}
Message-ID: {message_id}
{message}
------------------------
"""
# Print the email to console
print(email_format) # noqa: T201
# Return a success message
return (
f"Email successfully sent from {sender} to {recipient} at "
+ datetime.datetime.now(datetime.timezone.utc).strftime("%H:%M:%S")
)
# Create Gradio Interface
gr_send_email = gr.Interface(
fn=send_email,
inputs=["text", "text", "text"],
outputs="text",
title="Email Sender Simulator",
description="This tool simulates sending an email.",
)