From 67276a7e498597f19260de66d96a3f1ec1367f4b Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Tue, 2 May 2023 05:50:22 +0000 Subject: [PATCH] Send overdue emails --- apiserver/apiserver/api/emails/overdue.html | 26 +++++++++++++++++++++ apiserver/apiserver/api/emails/overdue.txt | 19 +++++++++++++++ apiserver/apiserver/api/utils.py | 13 +++++++---- apiserver/apiserver/api/utils_email.py | 26 ++++++++++++++++++++- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 apiserver/apiserver/api/emails/overdue.html create mode 100644 apiserver/apiserver/api/emails/overdue.txt diff --git a/apiserver/apiserver/api/emails/overdue.html b/apiserver/apiserver/api/emails/overdue.html new file mode 100644 index 0000000..97e6bff --- /dev/null +++ b/apiserver/apiserver/api/emails/overdue.html @@ -0,0 +1,26 @@ + + + + + + + +
Hi [name],
+

+
Your Protospace member dues are behind by two months and you are now "overdue".
+

+
You are paid up until [date]. Please pay your dues to prevent having your card and account deactivated by the system.
+

+
You can log into the portal and pay here:
+
https://my.protospace.ca/paymaster
+

+
Or send e-Transfer to info@protospace.ca or hand a director cash.
+

+
If there has been an error or you want to reply to this email, please click "reply-all" since the Spaceport inbox does not exist.
+

+
You won't recieve any other emails about this.
+

+
Thanks,
+
Spaceport
+ + diff --git a/apiserver/apiserver/api/emails/overdue.txt b/apiserver/apiserver/api/emails/overdue.txt new file mode 100644 index 0000000..cd651ee --- /dev/null +++ b/apiserver/apiserver/api/emails/overdue.txt @@ -0,0 +1,19 @@ +Hi [name], + +Your Protospace member dues are behind by two months and you are now "overdue". + +You are paid up until [date]. Please pay your dues to prevent having your +account and card deactivated by the system. + +You can log into the portal and pay here: +https://my.protospace.ca/paymaster + +Or send e-Transfer to info@protospace.ca or hand a director cash. + +If there has been an error or you want to reply to this email, please click +"reply-all" since the Spaceport inbox does not exist. + +You won't recieve any other emails about this. + +Thanks, +Spaceport diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index a4d91b7..9b3442e 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -115,10 +115,15 @@ def tally_membership_months(member, fake_date=None): alert_tanner(msg) logger.info(msg) - if status == 'Overdue' and previous_status == 'Due': - msg = 'Member has become Overdue: {} {}'.format(member.preferred_name, member.last_name) - alert_tanner(msg) - logger.info(msg) + if status == 'Overdue': + if previous_status == 'Due': + msg = 'Member has become Overdue: {} {}'.format(member.preferred_name, member.last_name) + alert_tanner(msg) + logger.info(msg) + + utils_email.send_overdue_email(member) + else: + logger.info('Skipping email because member wasn\'t due before.') member.save() logging.debug('Tallied %s membership months: updated.', member) diff --git a/apiserver/apiserver/api/utils_email.py b/apiserver/apiserver/api/utils_email.py index 8254f1c..d713da9 100644 --- a/apiserver/apiserver/api/utils_email.py +++ b/apiserver/apiserver/api/utils_email.py @@ -121,10 +121,34 @@ def send_usage_bill_email(user, device, month, minutes, overage, bill): subject='{} {} Usage Bill'.format(month, device), message=email_text, from_email=None, # defaults to DEFAULT_FROM_EMAIL - recipient_list=[user.email, 'directors@protospace.ca', 'protospace@tannercollin.com'], + recipient_list=[user.email, 'directors@protospace.ca', 'spaceport@tannercollin.com'], ) if not settings.EMAIL_HOST: time.sleep(0.5) # simulate slowly sending emails when logging to console logger.info('Sent usage bill email:\n' + email_text) + +def send_overdue_email(member): + def replace_fields(text): + return text.replace( + '[name]', member.preferred_name, + ).replace( + '[date]', member.expire_date.strftime('%B %d, %Y'), + ) + + with open(EMAIL_DIR + 'overdue.txt', 'r') as f: + email_text = replace_fields(f.read()) + + with open(EMAIL_DIR + 'overdue.html', 'r') as f: + email_html = replace_fields(f.read()) + + send_mail( + subject='Protospace member dues overdue', + message=email_text, + from_email=None, # defaults to DEFAULT_FROM_EMAIL + recipient_list=[member.user.email, 'directors@protospace.ca', 'spaceport@tannercollin.com'], + html_message=email_html, + ) + + logger.info('Sent overdue email:\n' + email_text)