fixed email sending for html content type

This commit is contained in:
Sam
2021-03-12 13:45:36 +00:00
parent ffb39ba62f
commit 5da01b318e
4 changed files with 9 additions and 2 deletions

View File

@@ -40,8 +40,8 @@ AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend" EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend"
DEFAULT_FROM_EMAIL = "no-reply@latienda.com" # DEFAULT_FROM_EMAIL = "no-reply@latienda.com"
# DEFAULT_FROM_EMAIL = "samuel.molina@enreda.coop" DEFAULT_FROM_EMAIL = "samuel.molina@enreda.coop"
SERVER_EMAIL = "mail-server@latienda.com" SERVER_EMAIL = "mail-server@latienda.com"

View File

@@ -65,11 +65,13 @@ class CompanyViewSet(viewsets.ModelViewSet):
# send email to company # send email to company
subject = "Contacto de usuario" subject = "Contacto de usuario"
email = EmailMessage(subject, company_message, to=[instance.creator.email]) email = EmailMessage(subject, company_message, to=[instance.creator.email])
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Email sent to {instance.creator.email} as manager of {instance.name}") logging.info(f"Email sent to {instance.creator.email} as manager of {instance.name}")
# send confirmation email to user # send confirmation email to user
subject = 'Confirmación de contacto' subject = 'Confirmación de contacto'
email = EmailMessage(subject, message, to=[request.user.email]) email = EmailMessage(subject, message, to=[request.user.email])
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Contact confirmation email sent to {request.user.email}") logging.info(f"Contact confirmation email sent to {request.user.email}")
stats_data = { stats_data = {
@@ -98,10 +100,12 @@ class CompanyViewSet(viewsets.ModelViewSet):
}) })
# send email to company # send email to company
email = EmailMessage(subject, company_message, to=[instance.creator.email]) email = EmailMessage(subject, company_message, to=[instance.creator.email])
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Email sent to {instance.creator.email} as manager of {instance.name}") logging.info(f"Email sent to {instance.creator.email} as manager of {instance.name}")
# send confirmation email to user # send confirmation email to user
email = EmailMessage(subject, user_message, to=[data['email']]) email = EmailMessage(subject, user_message, to=[data['email']])
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Contact confirmation email sent to anonymous user {data['email']}") logging.info(f"Contact confirmation email sent to anonymous user {data['email']}")
# statslog data to register interaction # statslog data to register interaction

View File

@@ -81,6 +81,7 @@ def send_verification_email(request, user):
email = EmailMessage( email = EmailMessage(
subject, message, to=[user.email] subject, message, to=[user.email]
) )
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Verification email sent to {user.email}") logging.info(f"Verification email sent to {user.email}")
except Exception as e: except Exception as e:

View File

@@ -301,6 +301,7 @@ def purchase_email(request):
}) })
subject = "[latienda.coop] Solicitud de compra" subject = "[latienda.coop] Solicitud de compra"
email = EmailMessage(subject, company_message, to=[company.email]) email = EmailMessage(subject, company_message, to=[company.email])
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Email sent to {company}") logging.info(f"Email sent to {company}")
# send confirmation email to user # send confirmation email to user
@@ -312,6 +313,7 @@ def purchase_email(request):
}) })
subject = 'Confirmación de petición de compra' subject = 'Confirmación de petición de compra'
email = EmailMessage(subject, user_message, to=[user_email]) email = EmailMessage(subject, user_message, to=[user_email])
email.content_subtype = "html"
email.send() email.send()
logging.info(f"Purchase Contact confirmation email sent to {user_email}") logging.info(f"Purchase Contact confirmation email sent to {user_email}")
except Exception as e: except Exception as e: