File size: 2,282 Bytes
23b379c
 
 
0d4024a
 
23b379c
0d4024a
 
23b379c
 
 
10931f7
23b379c
0d4024a
 
 
 
23b379c
 
 
 
 
 
0d4024a
 
 
 
 
 
 
 
 
 
 
 
10931f7
 
 
23b379c
0d4024a
23b379c
 
0d4024a
 
 
23b379c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d4024a
23b379c
 
0d4024a
 
 
 
23b379c
 
 
 
 
10931f7
23b379c
 
0d4024a
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
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.",
)