From ac087998f3a087267e7e348fcc2395104963d15e Mon Sep 17 00:00:00 2001 From: preranaandure Date: Thu, 16 May 2024 14:28:08 +0800 Subject: [PATCH] Add headers to the email --- wildlifecompliance/components/emails/emails.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wildlifecompliance/components/emails/emails.py b/wildlifecompliance/components/emails/emails.py index 07caa3643..86f9c3645 100644 --- a/wildlifecompliance/components/emails/emails.py +++ b/wildlifecompliance/components/emails/emails.py @@ -44,7 +44,8 @@ def send( context=None, attachments=None, cc=None, - bcc=None): + bcc=None, + headers=None): """ Send an email using EmailMultiAlternatives with text and html. :param to_addresses: a string or a list of addresses @@ -57,6 +58,10 @@ def send( :param cc: :return: """ + headers = {} + email_instance = 'DEV' + if hasattr(settings, 'EMAIL_INSTANCE'): + email_instance = settings.EMAIL_INSTANCE # The next line will throw a TemplateDoesNotExist if html template # cannot be found html_template = loader.get_template(self.html_template) @@ -89,6 +94,7 @@ def send( _attachments.append((filename, content, mime)) else: _attachments.append(attachment) + headers['System-Environment'] = email_instance msg = EmailMultiAlternatives( self.subject, txt_body, @@ -96,7 +102,8 @@ def send( to=to_addresses, attachments=_attachments, cc=cc, - bcc=bcc) + bcc=bcc, + headers=headers) msg.attach_alternative(html_body, 'text/html') try: msg.send(fail_silently=False)