Spaces:
Runtime error
Runtime error
import gradio as gr | |
import datetime | |
import random | |
def send_email(recipient, subject, message): | |
""" | |
Simulates sending an email from [email protected] and prints it to the console in a well-formatted way. | |
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]. | |
Parameters: | |
----------- | |
recipient : str | |
The email address of the recipient (To field) | |
subject : str | |
The subject line of the email | |
message : str | |
The main body content of the email | |
Returns: | |
-------- | |
str | |
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' | |
""" | |
# Fixed sender email | |
sender = "[email protected]" | |
# Generate a random message ID | |
message_id = f"<{random.randint(100000, 999999)}.{random.randint(1000000000, 9999999999)}@mail-server>" | |
# Get current timestamp | |
timestamp = datetime.datetime.now().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) | |
# Return a success message | |
return f"Email successfully sent from {sender} to {recipient} at {datetime.datetime.now().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 by formatting and printing it to the console." | |
) | |