diff --git a/.env.example b/.env.example index 3684287..cad53fc 100644 --- a/.env.example +++ b/.env.example @@ -3,6 +3,8 @@ WATCH_INTERVAL=300 # Emails will this subject will be replied to # (also looks for "Re: ") SUBJECT_KEY="llmail autoreply" +# This is the alias that the LLM will use when sending emails +ALIAS = "LLMail" # This message will be prepended to the message history sent to the LLM as a message from the system role # Use this for customizing the behavior of the LLM and hence the nature of the responses SYSTEM_PROMPT= diff --git a/llmail/__main__.py b/llmail/__main__.py index c3a7ca7..cf26408 100644 --- a/llmail/__main__.py +++ b/llmail/__main__.py @@ -98,6 +98,7 @@ def main(): while True: fetch_and_process_emails( subject=args.subject_key, + alias=args.alias, system_prompt=args.system_prompt, ) time.sleep(args.watch_interval) @@ -106,11 +107,13 @@ def main(): else: fetch_and_process_emails( subject=args.subject_key, + alias=args.alias, system_prompt=args.system_prompt, ) def fetch_and_process_emails( subject: str, + alias: str = None, system_prompt: str = None, ): """Fetch and process emails from the IMAP server.""" @@ -227,6 +230,7 @@ def fetch_and_process_emails( send_reply( thread=get_thread_history(client, email_thread), subject=subject, + alias=args.alias, client=client, msg_id=msg_id, message_id=message_id, @@ -407,6 +411,7 @@ def set_primary_logger(log_level): def send_reply( thread: list[dict], subject: str, + alias: str, client: IMAPClient, msg_id: int, message_id: str, @@ -438,7 +443,7 @@ def send_reply( generated_response = generated_response.choices[0].message.content logger.debug(f"Generated response: {generated_response}") yag = yagmail.SMTP( - user=args.smtp_username, + user={args.smtp_username: alias} if alias else args.smtp_username, password=args.smtp_password, host=args.smtp_host, port=int(args.smtp_port), diff --git a/llmail/utils/cli_args.py b/llmail/utils/cli_args.py index 28c94d0..7a48af9 100644 --- a/llmail/utils/cli_args.py +++ b/llmail/utils/cli_args.py @@ -89,6 +89,11 @@ def set_argparse(): help="Emails with this subject will be replied to", default=os.getenv("SUBJECT_KEY") if os.getenv("SUBJECT_KEY") else "llmail autoreply", ) + email.add_argument( + "--alias", + help="Name to use in the 'From' in addition to the email address", + default=os.getenv("ALIAS") if os.getenv("ALIAS") else "LLMail", + ) imap = email.add_argument_group("IMAP") imap.add_argument("--imap-host", help="IMAP server hostname", default=os.getenv("IMAP_HOST")) imap.add_argument("--imap-port", help="IMAP server port", default=os.getenv("IMAP_PORT"))