Skip to content

Commit

Permalink
Merge pull request #254 from preranaandure/master
Browse files Browse the repository at this point in the history
Add headers to the email
  • Loading branch information
xzzy authored May 16, 2024
2 parents 8040897 + ac08799 commit 57da7c2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions wildlifecompliance/components/emails/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -89,14 +94,16 @@ def send(
_attachments.append((filename, content, mime))
else:
_attachments.append(attachment)
headers['System-Environment'] = email_instance
msg = EmailMultiAlternatives(
self.subject,
txt_body,
from_email=from_address,
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)
Expand Down

0 comments on commit 57da7c2

Please sign in to comment.