Skip to content

Commit

Permalink
feat: add multiple recipients to mail (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
seblum authored Jul 3, 2024
1 parent 651feaf commit 6379ab1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ run-dev:
# Build Docker image
docker-build:
poetry_version=$(poetry version | awk '{print $2}')
docker build -t slotbookertest:${poetry_version} -f poetry.Dockerfile .
docker build -t slotbookertest:v${poetry_version} -f poetry.Dockerfile .

# Run Docker container
docker-run:
poetry_version=$(poetry version | awk '{print $2}')
docker run -it --env-file .env \
--volume $(pwd)/octiv-booker/src/slotbooker/data/:/app/slotbooker/data/ \
slotbookertest:${poetry_version}
slotbookertest:v${poetry_version}

# Build and run Docker container
docker-full:
Expand Down
10 changes: 7 additions & 3 deletions src/slotbooker/utils/gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ssl
import smtplib


def send_logs_to_mail(filename: str) -> None:
"""Send an email with the content of the specified file as the email body.
Expand Down Expand Up @@ -31,17 +32,20 @@ def send_logs_to_mail(filename: str) -> None:
email_password = os.getenv("EMAIL_PASSWORD")
email_receiver = os.getenv("EMAIL_RECEIVER")

# Convert the string to a list
email_receiver_list = email_receiver.split(";")

# read email body from logs
subject = "OctivBooker report"
with open(filename) as fp:
body = fp.read()

# body = format_to_html(body)

# build email
em = EmailMessage()
em["From"] = email_sender
em["To"] = email_receiver
em["To"] = " .".join(email_receiver_list)
em["Subject"] = subject
em.set_content(body, "plain")

Expand All @@ -50,6 +54,6 @@ def send_logs_to_mail(filename: str) -> None:
# send email
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as smtp:
smtp.login(email_sender, email_password)
smtp.sendmail(email_sender, email_receiver, em.as_string())
smtp.sendmail(email_sender, email_receiver_list, em.as_string())

print("email_sent")

0 comments on commit 6379ab1

Please sign in to comment.