-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from WATonomous/jimmy/update-email-template
update email template
- Loading branch information
Showing
1 changed file
with
25 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
@@ -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: | ||
|
@@ -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") | ||
|