prototype / src /mailing.py
fvde's picture
Upload folder using huggingface_hub
b2ecf83
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)