fix add_outgoing_email to return false if emails cant be validated

This commit is contained in:
Stephan Telling 2017-05-21 15:04:51 +02:00
parent e185da7436
commit 63648cd08e
No known key found for this signature in database
GPG key ID: D4892289F36ADA9B

View file

@ -1,5 +1,6 @@
from django.core.mail import EmailMultiAlternatives
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from django.core.files.base import ContentFile
from django.conf import settings
from django.template.loader import render_to_string
@ -65,7 +66,7 @@ def add_outgoing_email(
attachment_filename=''
):
""" adds an email to the outgoing queue
recipients is either just a str email or a str commaseperated emails
recipients is a string, if theres multiple emails seperate with a comma
"""
text_template = render_to_string(text_template, formatdict)
@ -74,9 +75,15 @@ def add_outgoing_email(
if ',' in recipients:
for recipient in recipients.split(','):
validate_email(recipient.strip())
try:
validate_email(recipient.strip())
except ValidationError:
return False
else:
validate_email(recipients)
try:
validate_email(recipients)
except ValidationError:
return False
email = OutgoingEmail.objects.create(
text_template=text_template,