Get first signup email through

This commit is contained in:
Aarni Halinen
2020-07-16 13:27:18 +03:00
parent f9e7c4a904
commit 39ab86fe3e
3 changed files with 21 additions and 30 deletions
-9
View File
@@ -7,9 +7,6 @@ from django.utils.translation import ugettext as _
from django.db.models.signals import post_save
from django.dispatch import receiver
import logging
from smtplib import SMTPAuthenticationError
from members.models import Member, Request
from webapp.utils import send_email
@@ -20,13 +17,10 @@ def email_on_request(sender, instance, created, **kwargs):
if not settings.ENABLE_AUTOMATIC_EMAILS:
return
try:
if created:
subject = 'Test1'
message = 'Please validate your email address\r\n'
send_email(instance.email, subject, message)
except SMTPAuthenticationError:
logging.error('Failed to send email to accepted request!')
@receiver(post_save, sender=Member)
@@ -35,10 +29,7 @@ def email_on_accept(sender, instance, created, **kwargs):
if not settings.ENABLE_AUTOMATIC_EMAILS:
return
try:
if created:
subject = 'Test2'
message = 'Jäsenhakemuksesi on hyväksytty!!!\r\n'
send_email(instance.email, subject, message)
except SMTPAuthenticationError:
logging.error('Failed to send email to accepted member!')
+8 -7
View File
@@ -14,7 +14,6 @@ from phonenumber_field.modelfields import PhoneNumberField
from django.contrib.postgres.fields import JSONField
from uuid import uuid4
import logging
from smtplib import SMTPAuthenticationError
VERBOSE_NAME = _('Webapp')
EMAIL_REGEX = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
@@ -186,18 +185,20 @@ class Signup(models.Model):
@receiver(post_save, sender=Signup)
def email_on_singup(sender, instance, created, **kwargs):
def email_on_signup(sender, instance, created, **kwargs):
"""Send email validation."""
if not settings.ENABLE_AUTOMATIC_EMAILS:
return
try:
if created and instance.email:
# TODO: Possible bug due to many-to-many relationship with events and forms.
subject = _(f"Olet ilmoittautunut tapahtumaan {instance.signupForm.event.first().title}")
# TODO: Subject field crashes with lazy loaded translations.
try:
# subject = _(f"Olet ilmoittautunut tapahtumaan {instance.signupForm.event.first().title}")
subject = f"Olet ilmoittautunut tapahtumaan {instance.signupForm.event.first().title}"
except AttributeError:
# subject = _(f"Olet ilmoittautunut ilmoon {instance.signupForm.title}")
subject = f"Olet ilmoittautunut ilmoon {instance.signupForm.title}"
send_signup_email(instance.email, subject, instance.id, instance.uuid)
except SMTPAuthenticationError:
logging.error('Failed to send email to signup')
class BaseRole(models.Model):
+2 -3
View File
@@ -42,13 +42,12 @@ def send_email(to, subject, body, fail_silently=False):
}
success = mailjet.send.create(data=data)
if success.status_code != 201:
# For some reason returns 200 OK instead of 201 Created...
if success.status_code != 200:
raise Exception(f'Failed to send email: {success.json()}')
except Exception as ex:
logging.exception('Failed to send email.')
logging.debug(EMAIL_API_KEY)
logging.debug(EMAIL_API_SECRET)
def send_signup_email(to, subject, id, uuid):