diff --git a/src/teams/email.py b/src/teams/email.py index 8a90e82c..8917241b 100644 --- a/src/teams/email.py +++ b/src/teams/email.py @@ -49,9 +49,7 @@ def send_new_membership_email(membership): return add_outgoing_email( text_template='emails/new_membership_email.txt', html_template='emails/new_membership_email.html', - recipients=', '.join( - [resp.email for resp in membership.team.responsible] - ), + recipients=membership.team.responsible, formatdict=formatdict, subject='New membership request for {} at {}'.format( membership.team.name, diff --git a/src/utils/email.py b/src/utils/email.py index c0899bb8..fbb90d78 100644 --- a/src/utils/email.py +++ b/src/utils/email.py @@ -66,22 +66,19 @@ def add_outgoing_email( attachment_filename='' ): """ adds an email to the outgoing queue - recipients is a string, if theres multiple emails seperate with a comma + recipients is a list of to recipients """ text_template = render_to_string(text_template, formatdict) if html_template: html_template = render_to_string(html_template, formatdict) - if ',' in recipients: - for recipient in recipients.split(','): - try: - validate_email(recipient.strip()) - except ValidationError: - return False - else: + if not isinstance(recipients, list): + recipients = [recipients] + + for recipient in recipients: try: - validate_email(recipients) + validate_email(recipient) except ValidationError: return False diff --git a/src/utils/models.py b/src/utils/models.py index 5095c1f6..4710f4fc 100644 --- a/src/utils/models.py +++ b/src/utils/models.py @@ -1,4 +1,5 @@ import uuid +from django.contrib.postgres.fields import ArrayField from django.core.exceptions import ValidationError from django.contrib import messages from django.db import models @@ -74,7 +75,6 @@ class OutgoingEmail(CreatedUpdatedModel): subject = models.CharField(max_length=500) text_template = models.TextField() html_template = models.TextField(blank=True) - recipient = models.CharField(max_length=500) sender = models.CharField(max_length=500) attachment = models.FileField(blank=True) processed = models.BooleanField(default=False)