|
|
import datetime |
|
|
import random |
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
def send_email(recipient: str, subject: str, message: str) -> str: |
|
|
"""Simulates sending an email from cert@company.com. |
|
|
|
|
|
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 cert@company.com. |
|
|
|
|
|
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("jane@example.com", "Security Alert", "Please update your password.") |
|
|
------ EMAIL SENT ------ |
|
|
From: cert@company.com |
|
|
To: jane@example.com |
|
|
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 jane@example.com at 16:40:58' |
|
|
""" |
|
|
|
|
|
sender = "cert@company.com" |
|
|
|
|
|
|
|
|
message_id = f"<{random.randint(100000, 999999)}.{random.randint(1000000000, 9999999999)}@mail-server>" |
|
|
|
|
|
|
|
|
timestamp = datetime.datetime.now(datetime.timezone.utc).strftime( |
|
|
"%a, %d %b %Y %H:%M:%S +0000", |
|
|
) |
|
|
|
|
|
|
|
|
email_format = f""" |
|
|
------ EMAIL SENT ------ |
|
|
From: {sender} |
|
|
To: {recipient} |
|
|
Subject: {subject} |
|
|
Date: {timestamp} |
|
|
Message-ID: {message_id} |
|
|
|
|
|
{message} |
|
|
------------------------ |
|
|
""" |
|
|
|
|
|
|
|
|
print(email_format) |
|
|
|
|
|
|
|
|
return ( |
|
|
f"Email successfully sent from {sender} to {recipient} at " |
|
|
+ datetime.datetime.now(datetime.timezone.utc).strftime("%H:%M:%S") |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
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.", |
|
|
) |
|
|
|