Skip to content

Commit

Permalink
Merge pull request #221 from kartoza/use-cid-to-display-images-in-emails
Browse files Browse the repository at this point in the history
Use cid to display images in emails
  • Loading branch information
tinashechiraya authored Jan 13, 2025
2 parents 9b01d6d + a54f6c0 commit a98e4f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions django_project/core/custom_auth_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from rest_framework.decorators import api_view
from django.contrib.auth import logout
from allauth.account.models import EmailAddress
from email.mime.image import MIMEImage
from django.contrib.staticfiles.finders import find


@api_view(["POST"])
Expand Down Expand Up @@ -134,6 +136,12 @@ def post(self, request, *args, **kwargs):
from_email=settings.NO_REPLY_EMAIL,
to=[email]
)
logo_path = find('images/main_logo.svg')

if logo_path:
with open(logo_path, 'rb') as img_file:
image = MIMEImage(img_file.read(), _subtype="svg+xml")
image.add_header('Content-ID', '<logo_image>')
email_message.attach_alternative(html_message, "text/html")
email_message.send()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<tr>
<!-- Left Column: Logo -->
<td align="left" width="50%" style="padding: 10px;">
<img src="https://arw.dev.do.kartoza.com/static/images/main_logo.svg" alt="Logo" width="200" style="display: block;">
<img src="cid:logo_image" alt="Logo" width="200" style="display: block;">
</td>
<td align="right" width="50%" style="padding: 10px; color: #ffffff; font-family: Helvetica,sans-serif;">
<h2 style="margin: 0; font-size: 24px;">Africa Rangeland Watch</h2>
Expand Down

0 comments on commit a98e4f5

Please sign in to comment.