From 5e5ce02759a616ff77f87656d5d0a3b67404f8f1 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 4 Jul 2022 14:57:34 +0530 Subject: [PATCH] feat: instance created notification email template with nicer body --- .../emails/instance-created.txt | 11 ++++++++ infrastructure/utils.py | 26 +++++++++++-------- 2 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 infrastructure/templates/infrastructure/emails/instance-created.txt diff --git a/infrastructure/templates/infrastructure/emails/instance-created.txt b/infrastructure/templates/infrastructure/emails/instance-created.txt new file mode 100644 index 0000000..15f4f7d --- /dev/null +++ b/infrastructure/templates/infrastructure/emails/instance-created.txt @@ -0,0 +1,11 @@ +Hello {{ username }}!, + +The deployment job has run to completion and your Hostea instance is now online! +Credentials to admin account was sent in an earlier email, please contact +support if didn't receive it. + +Gitea: {{ gitea_uri }} +Woodpecker CI: {{ woodpecker_uri }} + +Cheers, +Hostea team diff --git a/infrastructure/utils.py b/infrastructure/utils.py index 45393a5..707cbc6 100644 --- a/infrastructure/utils.py +++ b/infrastructure/utils.py @@ -53,19 +53,23 @@ class Worker(Thread): job = self.job self.job = None email = job.instance.owned_by.email + + ctx = { + "gitea_uri": gitea_uri, + "woodpecker_uri": woodpecker, + "username": job.instance.owned_by.username, + } + body = render_to_string( + "infrastructure/emails/instance-created.txt", + context=ctx, + ) + + sender = settings.HOSTEA["EMAIL_SENDER_ADDRESS"] + send_mail( subject="[Hostea] Your Hostea instance is now online!", - message=f""" -Hello, - -The deployment job has run to completion and your Hostea instance is now online! -Credentials to admin account was sent in an earlier email, please contact -support if didn't receive it. - -Gitea: {gitea_uri} -Woodpecker CI: {woodpecker} -""", - from_email="No reply Hostea", # TODO read from settings.py + message=body, + from_email=f"No reply Hostea<{sender}>", # TODO read from settings.py recipient_list=[email], ) job.delete()