Handle errors when sending welcome emails during member registraton
This commit is contained in:
parent
1cf333f0fc
commit
9f23f85b87
1 changed files with 21 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
import uuid
|
||||
from datetime import timedelta
|
||||
from smtplib import SMTPRecipientsRefused
|
||||
|
||||
import unicodecsv
|
||||
from custommail.shortcuts import send_custom_mail
|
||||
|
@ -445,6 +446,25 @@ def registration_form2(request, login_clipper=None, username=None, fullname=None
|
|||
)
|
||||
|
||||
|
||||
def notify_new_member(request, member: User):
|
||||
if not member.email:
|
||||
messages.warning(
|
||||
request,
|
||||
"GestioCOF n'a pas d'adresse mail pour {}, ".format(member)
|
||||
+ "aucun email de bienvenue n'a été envoyé",
|
||||
)
|
||||
# Try to send a welcome email and report SMTP errors
|
||||
try:
|
||||
send_custom_mail(
|
||||
"welcome", "cof@ens.fr", [member.email], context={"member": member}
|
||||
)
|
||||
except SMTPRecipientsRefused:
|
||||
messages.error(
|
||||
request,
|
||||
"Error lors de l'envoi de l'email de bienvenue à {}".format(member.email),
|
||||
)
|
||||
|
||||
|
||||
@buro_required
|
||||
def registration(request):
|
||||
if request.POST:
|
||||
|
@ -494,12 +514,7 @@ def registration(request):
|
|||
# Enregistrement du profil
|
||||
profile = profile_form.save()
|
||||
if profile.is_cof and not was_cof:
|
||||
send_custom_mail(
|
||||
"welcome",
|
||||
"cof@ens.fr",
|
||||
[member.email],
|
||||
context={"member": member},
|
||||
)
|
||||
notify_new_member(request, member)
|
||||
# Enregistrement des inscriptions aux événements
|
||||
for form in event_formset:
|
||||
if "status" not in form.cleaned_data:
|
||||
|
|
Loading…
Reference in a new issue