From fbe0396a8e1b6d03d0b479387aa84ae970b41cd5 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Tue, 10 Mar 2020 20:40:12 +1100 Subject: [PATCH] Add command to send renewal emails --- .../jinja2/ssmembership/email/onboard.txt | 33 --------- .../email/{onboard.html => renew.html} | 24 ++---- .../jinja2/ssmembership/email/renew.txt | 31 ++++++++ .../management/commands/send_renewal_email.py | 73 +++++++++++++++++++ 4 files changed, 112 insertions(+), 49 deletions(-) delete mode 100644 ssmembership/jinja2/ssmembership/email/onboard.txt rename ssmembership/jinja2/ssmembership/email/{onboard.html => renew.html} (56%) create mode 100644 ssmembership/jinja2/ssmembership/email/renew.txt create mode 100644 ssmembership/management/commands/send_renewal_email.py diff --git a/ssmembership/jinja2/ssmembership/email/onboard.txt b/ssmembership/jinja2/ssmembership/email/onboard.txt deleted file mode 100644 index 7bd3d4b..0000000 --- a/ssmembership/jinja2/ssmembership/email/onboard.txt +++ /dev/null @@ -1,33 +0,0 @@ -{# - Society Self-Service - Copyright © 2018-2019 Yingtong Li (RunasSudo) - - Design by SendWithUs (Apache 2.0 licence) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -#} -Dear {{ name }}, - -{% if purchased %}Thank you for your recent purchase of a {{ import('django.conf').settings.ORG_NAME }} membership.{% else %}Thank you for your recent purchase of {{ import('django.conf').settings.ORG_NAME }} tickets or merchandise. Your purchase entitles you to membership of {{ import('django.conf').settings.ORG_NAME }} at no additional cost.{% endif %} You can activate your membership now by going to the link below or visiting {{ baseurl }}{{ url('monboard_index') }}. The process is very quick and should take less than a minute. - -By activating your membership, you'll be able to purchase future tickets at discounted member prices, nominate for election to the {{ import('django.conf').settings.ORG_NAME }} committee, and receive personalised weekly emails with relevant news and events from around the Monash Medicine community. - -Activate membership now: -{{ baseurl }}{{ renew_url }} - -If you do not want to activate your membership, or you are not a Monash medical student, simply ignore this email. - -If you encounter any issues activating your membership, or have any other questions, please contact the Secretary, Yingtong Li, at {{ import('django.conf').settings.AWS_SENDER_EMAIL }}. - -Please note that emails are being sent in stages. If other students have not received this email, please let them know that this is normal, and they should receive their email within 7 days. Otherwise, contact {{ import('django.conf').settings.AWS_SENDER_EMAIL }}. diff --git a/ssmembership/jinja2/ssmembership/email/onboard.html b/ssmembership/jinja2/ssmembership/email/renew.html similarity index 56% rename from ssmembership/jinja2/ssmembership/email/onboard.html rename to ssmembership/jinja2/ssmembership/email/renew.html index 448faee..935d186 100644 --- a/ssmembership/jinja2/ssmembership/email/onboard.html +++ b/ssmembership/jinja2/ssmembership/email/renew.html @@ -2,7 +2,7 @@ {# Society Self-Service - Copyright © 2018-2019 Yingtong Li (RunasSudo) + Copyright © 2018-2020 Yingtong Li (RunasSudo) Design by SendWithUs (Apache 2.0 licence) @@ -26,23 +26,15 @@ diff --git a/ssmembership/jinja2/ssmembership/email/renew.txt b/ssmembership/jinja2/ssmembership/email/renew.txt new file mode 100644 index 0000000..00d8ca3 --- /dev/null +++ b/ssmembership/jinja2/ssmembership/email/renew.txt @@ -0,0 +1,31 @@ +{# + Society Self-Service + Copyright © 2018-2020 Yingtong Li (RunasSudo) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +#} +Dear {{ name }}, + +{{ import('django.conf').settings.ORG_NAME }} is required by law to review its membership annually. You can renew your membership for free by going to the link below or visiting {{ baseurl }}{{ url('renew_index') }}. The process is very quick and should take less than a minute. + +Renew membership now: +{{ baseurl }}{{ renew_url }} + +If you do not renew your membership by **31 March {{ import('datetime').datetime.now().strftime('%Y') }}**, your membership will expire, and you will not be able to buy tickets to MUMUS events at member prices or run for election within MUMUS without becoming a member again. Please make sure to renew your membership by 31 March {{ import('datetime').datetime.now().strftime('%Y') }} to avoid this. + +If you do not want to renew your membership, or you are no longer a Monash medical student, simply ignore this email. + +If you encounter any issues renewing your membership, or have any other questions, please contact the Secretary, Dinali Panagodage, at {{ import('django.conf').settings.AWS_SENDER_EMAIL }}. + +Please note that emails are being sent in stages. If other students have not received this email, please let them know that this is normal, and they should receive their email within 7 days. Otherwise, contact {{ import('django.conf').settings.AWS_SENDER_EMAIL }}. diff --git a/ssmembership/management/commands/send_renewal_email.py b/ssmembership/management/commands/send_renewal_email.py new file mode 100644 index 0000000..08e9f26 --- /dev/null +++ b/ssmembership/management/commands/send_renewal_email.py @@ -0,0 +1,73 @@ +# Society Self-Service +# Copyright © 2018-2020 Yingtong Li (RunasSudo) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from ssmain.email import Emailer + +from django.core.management.base import BaseCommand, CommandError + +from django.conf import settings +from django.template import loader +from django.urls import reverse +from django.utils import timezone + +from ssmembership import models + +import hmac +import logging +import premailer +import time +import urllib.parse + +class Command(BaseCommand): + help = 'Send emails for membership renewal' + + def add_arguments(self, parser): + parser.add_argument('ids', nargs='*', type=int, help='Members with ID numbers equal to these values will be emailed (default all)') + parser.add_argument('--render', action='store_true', help='Render to stdout instead of sending emails') + + def handle(self, *args, **options): + today = timezone.localtime(timezone.now()).date() + + template_html = loader.get_template('ssmembership/email/renew.html') + template_txt = loader.get_template('ssmembership/email/renew.txt') + + if len(options['ids']) > 0: + members = models.Member.objects.filter(id__in=options['ids']) + else: + raise Exception('Must provide IDs') + + emailer = Emailer() + for member in members: + #import pdb; pdb.set_trace() + if member.member_type != 1 or member.expires < today or member.expires > today.replace(month=12, day=31): + self.stdout.write('Skipping {} at {}'.format(member.id, member.email)) + continue + + self.stdout.write('Emailing {} at {}'.format(member.id, member.email)) + + sig = hmac.new(settings.SECRET_KEY_MEMBERSIG.encode('utf-8'), member.email.encode('utf-8'), 'sha256').hexdigest() + renew_url = reverse('renew_signed') + '?' + urllib.parse.urlencode({'email': member.email, 'sig': sig}) + + template_args = { + 'name': member.first_name.strip() + ' ' + member.last_name.strip(), + 'renew_url': renew_url, + 'baseurl': 'https://' + settings.ALLOWED_HOSTS[0] + } + + content_html = premailer.Premailer(template_html.render(template_args), cssutils_logging_level=logging.ERROR).transform() + content_txt = template_txt.render(template_args) + + emailer.send_raw_mail([member.email], '{} membership renewal'.format(settings.ORG_NAME), content_txt, content_html)
-
Welcome to {{ import('django.conf').settings.ORG_NAME }}!
+
Membership renewal

Dear {{ name }},

-

- {% if purchased %} - Thank you for your recent purchase of a {{ import('django.conf').settings.ORG_NAME }} membership. - {% else %} - Thank you for your recent purchase of {{ import('django.conf').settings.ORG_NAME }} tickets or merchandise. Your purchase entitles you to membership of {{ import('django.conf').settings.ORG_NAME }} at no additional cost. - {% endif %} - You can activate your membership now by clicking the button below or visiting {{ baseurl }}{{ url('monboard_index') }}. The process is very quick and should take less than a minute. -

-

By activating your membership, you'll be able to purchase future tickets at discounted member prices, nominate for election to the {{ import('django.conf').settings.ORG_NAME }} committee, and receive personalised weekly emails with relevant news and events from around the Monash Medicine community.

-
- Activate membership now +

{{ import('django.conf').settings.ORG_NAME }} is required by law to review its membership annually. You can renew your membership for free by clicking the button below or visiting {{ baseurl }}{{ url('renew_index') }}. The process is very quick and should take less than a minute.

+ -
-

If you do not want to activate your membership, or you are not a Monash medical student, simply ignore this email.

-

If you encounter any issues activating your membership, or have any other questions, please contact the Secretary, Yingtong Li, at {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.

+

If you do not renew your membership by 31 March {{ import('datetime').datetime.now().strftime('%Y') }}, your membership will expire, and you will not be able to buy tickets to {{ import('django.conf').settings.ORG_NAME }} events at member prices or run for election within {{ import('django.conf').settings.ORG_NAME }} without becoming a member again. If you would like to become a member again after that date, you can either purchase membership for $5, or purchase {{ import('django.conf').settings.ORG_NAME }} merchandise or a ticket to a {{ import('django.conf').settings.ORG_NAME }} event.

+

If you do not want to renew your membership, or you are no longer a Monash medical student, simply ignore this email.

+

If you encounter any issues renewing your membership, or have any other questions, please contact the Secretary, Dinali Panagodage, at {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.

Please note that emails are being sent in stages. If other students have not received this email, please let them know that this is normal, and they should receive their email within 7 days. Otherwise, contact {{ import('django.conf').settings.AWS_SENDER_EMAIL }}.