From 5da01b318ec5515a843fc8271e9a5883ce1eb49a Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 12 Mar 2021 13:45:36 +0000 Subject: [PATCH] fixed email sending for html content type --- back_latienda/settings/production.py | 4 ++-- companies/views.py | 4 ++++ core/utils.py | 1 + products/views.py | 2 ++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/back_latienda/settings/production.py b/back_latienda/settings/production.py index 653acc2..f506476 100644 --- a/back_latienda/settings/production.py +++ b/back_latienda/settings/production.py @@ -40,8 +40,8 @@ AWS_DEFAULT_ACL = None DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend" -DEFAULT_FROM_EMAIL = "no-reply@latienda.com" -# DEFAULT_FROM_EMAIL = "samuel.molina@enreda.coop" +# DEFAULT_FROM_EMAIL = "no-reply@latienda.com" +DEFAULT_FROM_EMAIL = "samuel.molina@enreda.coop" SERVER_EMAIL = "mail-server@latienda.com" diff --git a/companies/views.py b/companies/views.py index 62c4767..97e2897 100644 --- a/companies/views.py +++ b/companies/views.py @@ -65,11 +65,13 @@ class CompanyViewSet(viewsets.ModelViewSet): # send email to company subject = "Contacto de usuario" email = EmailMessage(subject, company_message, to=[instance.creator.email]) + email.content_subtype = "html" email.send() logging.info(f"Email sent to {instance.creator.email} as manager of {instance.name}") # send confirmation email to user subject = 'Confirmación de contacto' email = EmailMessage(subject, message, to=[request.user.email]) + email.content_subtype = "html" email.send() logging.info(f"Contact confirmation email sent to {request.user.email}") stats_data = { @@ -98,10 +100,12 @@ class CompanyViewSet(viewsets.ModelViewSet): }) # send email to company email = EmailMessage(subject, company_message, to=[instance.creator.email]) + email.content_subtype = "html" email.send() logging.info(f"Email sent to {instance.creator.email} as manager of {instance.name}") # send confirmation email to user email = EmailMessage(subject, user_message, to=[data['email']]) + email.content_subtype = "html" email.send() logging.info(f"Contact confirmation email sent to anonymous user {data['email']}") # statslog data to register interaction diff --git a/core/utils.py b/core/utils.py index 4fd5e41..ad0f96e 100644 --- a/core/utils.py +++ b/core/utils.py @@ -81,6 +81,7 @@ def send_verification_email(request, user): email = EmailMessage( subject, message, to=[user.email] ) + email.content_subtype = "html" email.send() logging.info(f"Verification email sent to {user.email}") except Exception as e: diff --git a/products/views.py b/products/views.py index f75efdb..c756044 100644 --- a/products/views.py +++ b/products/views.py @@ -301,6 +301,7 @@ def purchase_email(request): }) subject = "[latienda.coop] Solicitud de compra" email = EmailMessage(subject, company_message, to=[company.email]) + email.content_subtype = "html" email.send() logging.info(f"Email sent to {company}") # send confirmation email to user @@ -312,6 +313,7 @@ def purchase_email(request): }) subject = 'Confirmación de petición de compra' email = EmailMessage(subject, user_message, to=[user_email]) + email.content_subtype = "html" email.send() logging.info(f"Purchase Contact confirmation email sent to {user_email}") except Exception as e: