CoolFace
Apppublic

lenox-ai/prototype

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
mailing.py39 linesDownload Raw Back to src
1import webbrowser2import urllib.parse3from typing import List4 5 6def send_email(7    llm_text: str,8    recipients: str = "",9    subject: str = "",10    email_wrapping_content: str = "<TEXT_FROM_LLM>",11):12    """Send an email to the specified recipients.13 14    Args:15        recipients (List[str], optional): List of email addresses. Defaults to [""].16        subject (str): Subject of the email.17        email_content (_type_): Content of the email.18 19    Example usage:20    - send_email("test@example.com;test2@example.com", "Hello!", "This is the body of the email.")21    """22    recipients_list = recipients.split(";")23    email_addresses = ",".join([recipient.strip() for recipient in recipients_list])24 25    # URL encode the subject and email content to ensure it's correctly parsed26    subject = urllib.parse.quote(subject)27 28    if "<TEXT_FROM_LLM>" in email_wrapping_content:29        email_content = email_wrapping_content.replace("<TEXT_FROM_LLM>", llm_text)30    else:31        email_content = email_wrapping_content + "\n\n" + llm_text32    email_content = urllib.parse.quote(email_content)33 34    # Construct the mailto URL35    mailto_url = f"mailto:{email_addresses}?subject={subject}&body={email_content}"36 37    # Open the default email client38    webbrowser.open(mailto_url, new=2)39