Skip to content

Commit

Permalink
Merge pull request #6 from WATonomous/jimmy/update-email-template
Browse files Browse the repository at this point in the history
update email template
  • Loading branch information
Jimmyj30 authored Nov 19, 2023
2 parents d440274 + 895fb6f commit 3c95c2a
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions app/email.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import logging
import yaml
import json
import os
import aiosmtplib
from urllib.parse import quote
from email.message import EmailMessage
from app.constants import user_directory


logger = logging.getLogger('app-logger')
Expand All @@ -21,8 +19,28 @@ def generate_edit_link(user_config: dict) -> str:
return edit_link


def generate_email_content(edit_link: str):
return f"Sent via aiosmtplib! Here's your edit link: {edit_link}"
def generate_email_content(edit_link: str, user_config: dict):
name: str = user_config.get("general", {}).get("name")
if name is None:
name = "WATcloud user"
first_name:str = name.split(" ")[0]

email_body = (
f"<html>"
f"<head></head>"
f"<body><p>"
f"Hello {first_name},<br><br>"
f"Greetings from WATcloud! Your WATcloud user config edit link is ready for you:<br>"
f"<a href=\"{edit_link}\">Edit Link</a><br><br>"
f"If you have any questions or need assistance, don't hesitate to reach out"
f" to your WATcloud contact or the WATcloud team at"
f" <a href=\"mailto:[email protected]\">[email protected]</a>.<br><br>"
f"Vroom vroom,<br>"
f"WATcloud Team.<br>"
f"</p></body>"
f"<html>"
)
return email_body


async def send_email(user_config: dict, email_address: str) -> None:
Expand All @@ -31,8 +49,9 @@ async def send_email(user_config: dict, email_address: str) -> None:
message = EmailMessage()
message["From"] = "[email protected]"
message["To"] = email_address
message["Subject"] = "Hello World!"
message.set_content(generate_email_content(edit_link))
message["Subject"] = "WATcloud User Config Edit Link"
message["Reply-To"] = "[email protected]"
message.set_content(generate_email_content(edit_link, user_config), subtype='html')

username = os.getenv("EMAIL_ADDRESS")
password = os.getenv("EMAIL_PASSWORD")
Expand Down

0 comments on commit 3c95c2a

Please sign in to comment.