Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
feat: Add alias option for setting the 'From' name in emails
Browse files Browse the repository at this point in the history
  • Loading branch information
slashtechno committed May 12, 2024
1 parent 04612a9 commit 703e46a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ WATCH_INTERVAL=300
# Emails will this subject will be replied to
# (also looks for "Re: <SUBJECT>")
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=
Expand Down
7 changes: 6 additions & 1 deletion llmail/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 5 additions & 0 deletions llmail/utils/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 703e46a

Please sign in to comment.