File size: 2,274 Bytes
23b379c
 
 
 
 
10931f7
23b379c
10931f7
23b379c
 
 
10931f7
23b379c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10931f7
23b379c
10931f7
23b379c
10931f7
23b379c
 
 
10931f7
23b379c
 
 
10931f7
 
 
23b379c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10931f7
23b379c
 
 
 
 
10931f7
23b379c
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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."
)