Skip to content

Commit

Permalink
feat: Add Outlook settings to .env.example
Browse files Browse the repository at this point in the history
fix: Force `smtp_starttls` depending on `SSLError`
fix: Uncommented line that prevents multiple "Re: " prefixes
  • Loading branch information
slashtechno committed May 19, 2024
1 parent 5cb4278 commit 1396496
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
15 changes: 13 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SYSTEM_PROMPT=
# Set to "true" to redact email addresses or you can remove it (or set it to "false") to not redact email addresses
REDACT_EMAIL_ADDRESSES=true

OPENAI_API_KEY=""
OPENAI_API_KEY="..."
# At least when writing this, openrouter.ai has a free tier
OPENAI_BASE_URL="https://openrouter.ai/api/v1"
# The model to use for OpenAI
Expand All @@ -24,7 +24,7 @@ IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_USERNAME=[email protected]
# You'll probably need to use an app password if you're using Gmail, thought it might only be required instead of an account password if you have 2FA
IMAP_PASSWORD=
IMAP_PASSWORD=...
# Using All Mail for Gmail works the best as the program should be able to see sent emails as well as received emails
# If you're using a different email provider that doesn't have an All Mail folder, you might need to change this
# You can get a list of folders by running `llmail list-folders`
Expand All @@ -37,6 +37,17 @@ SMTP_PORT=465
SMTP_USERNAME=[email protected]
# Like with IMAP, you might need an app password
SMTP_PASSWORD=
# Outlook
# IMAP_HOST=imap-mail.outlook.com
# IMAP_PORT=993
# [email protected]
# IMAP_PASSWORD=...
# FOLDER="Inbox,Sent"
# SMTP_HOST=smtp-mail.outlook.com
# SMTP_PORT=587
# [email protected]
# SMTP_PASSWORD=...

# MESSAGE_ID_DOMAIN is the domain used in the Message-ID header
# Leave it empty or remove it if you don't want to use it as I'm not sure what the point would even be but it's here if you need it
MESSAGE_ID_DOMAIN=""
Expand Down
48 changes: 38 additions & 10 deletions llmail/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import timezone
import time
import re
from ssl import SSLError


from llmail.utils.cli_args import argparser
Expand Down Expand Up @@ -95,6 +96,7 @@ def main():
# Set up logging
set_primary_logger(args.log_level, args.redact_email_addresses)
logger.debug(args)
logger.info(f"Looking for emails that match the subject key \"{args.subject_key}\"")
if args.watch_interval:
logger.info(
f"Watching for new emails every {args.watch_interval} seconds"
Expand Down Expand Up @@ -480,16 +482,42 @@ def send_reply(
host=args.smtp_host,
port=int(args.smtp_port),
)
yag.send(
to=sender,
# subject=f"Re: {subject}" if not subject.startswith("Re: ") else subject,
subject=f"Re: {subject}",
headers={"In-Reply-To": message_id, "References": " ".join(references_ids)},
contents=generated_response,
message_id=make_msgid(
domain=args.message_id_domain if args.message_id_domain else "llmail"
),
)
try:
yag.send(
to=sender,
subject=f"Re: {subject}" if not subject.startswith("Re: ") else subject,
# subject=f"Re: {subject}",
headers={"In-Reply-To": message_id, "References": " ".join(references_ids)},
contents=generated_response,
message_id=make_msgid(
domain=args.message_id_domain if args.message_id_domain else "llmail"
),
)
except SSLError as e:
if "WRONG_VERSION_NUMBER" in str(e):
logger.info(
"SSL error occurred. Trying to connect with starttls=True instead."
)
yag = yagmail.SMTP(
user={args.smtp_username: alias} if alias else args.smtp_username,
password=args.smtp_password,
host=args.smtp_host,
port=int(args.smtp_port),
smtp_starttls=True,
smtp_ssl=False
)
yag.send(
to=sender,
subject=f"Re: {subject}" if not subject.startswith("Re: ") else subject,
# subject=f"Re: {subject}",
headers={"In-Reply-To": message_id, "References": " ".join(references_ids)},
contents=generated_response,
message_id=make_msgid(
domain=args.message_id_domain if args.message_id_domain else "llmail"
),
)
else:
raise e
# thread_from_msg_id = get_thread_history(client, msg_id)
# logger.debug(f"Thread history (message_identifier): {thread_from_msg_id}")
# logger.debug(f"Thread history length (message_identifier): {len(thread_from_msg_id)}")
Expand Down

0 comments on commit 1396496

Please sign in to comment.