File size: 1,287 Bytes
f2965eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb827f5
b2ecf83
 
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
import webbrowser
import urllib.parse
from typing import List


def send_email(
    llm_text: str,
    recipients: str = "",
    subject: str = "",
    email_wrapping_content: str = "<TEXT_FROM_LLM>",
):
    """Send an email to the specified recipients.

    Args:
        recipients (List[str], optional): List of email addresses. Defaults to [""].
        subject (str): Subject of the email.
        email_content (_type_): Content of the email.

    Example usage:
    - send_email("test@example.com;test2@example.com", "Hello!", "This is the body of the email.")
    """
    recipients_list = recipients.split(";")
    email_addresses = ",".join([recipient.strip() for recipient in recipients_list])

    # URL encode the subject and email content to ensure it's correctly parsed
    subject = urllib.parse.quote(subject)

    if "<TEXT_FROM_LLM>" in email_wrapping_content:
        email_content = email_wrapping_content.replace("<TEXT_FROM_LLM>", llm_text)
    else:
        email_content = email_wrapping_content + "\n\n" + llm_text
    email_content = urllib.parse.quote(email_content)

    # Construct the mailto URL
    mailto_url = f"mailto:{email_addresses}?subject={subject}&body={email_content}"

    # Open the default email client
    webbrowser.open(mailto_url, new=2)