Permalink
Browse files

- important fix : The send images as attachments was broken

  attachments were sent but the html tag was always containing inline images
  • Loading branch information...
1 parent e0972de commit 0a6b715b14c8c184385e1426d3b0bd143856de89 @macadames macadames committed Sep 29, 2011
Showing with 7 additions and 1 deletion.
  1. +3 −0 CHANGES.txt
  2. +4 −1 twistranet/notifier/handlers.py
View
3 CHANGES.txt
@@ -3,6 +3,9 @@ Trunk
- minor fix for mixed emails : the good mime type is multipart/related
+- important fix : The send images as attachments was broken
+ attachments were sent but the html tag was always containing inline images
+
1.1.3, 2011/09/15
=================
View
5 twistranet/notifier/handlers.py
@@ -214,7 +214,6 @@ def __call__(self, sender, **kwargs):
# Prepare messages
msg = EmailMultiAlternatives(subject, text_content, from_email, [ to ], )
if html_content:
- msg.attach_alternative(html_content, "text/html")
if getattr(settings, 'SEND_EMAIL_IMAGES_AS_ATTACHMENTS', DEFAULT_SEND_EMAIL_IMAGES_AS_ATTACHMENTS):
# we replace img links by img Mime Images
mimeimages = []
@@ -240,6 +239,7 @@ def replace_img_url(match):
img_url_expr = re.compile('(?P<attribute>src)\s*=\s*([\'\"])(%s)?(?P<urlpath>[^\"\']*)\\2' %domain, re.IGNORECASE)
html_content = img_url_expr.sub(replace_img_url, html_content)
+ msg.attach_alternative(html_content, "text/html")
if mimeimages:
msg.mixed_subtype = 'related'
for fkey, name, is_static in mimeimages:
@@ -255,6 +255,9 @@ def replace_img_url(match):
msgImage.add_header('Content-ID', '<%s>' % name)
msgImage.add_header('Content-Disposition', 'inline')
msg.attach(msgImage)
+ # just inline images
+ else:
+ msg.attach_alternative(html_content, "text/html")
# Send safely
try:
log.debug("Sending mail: '%s' from '%s' to '%s'" % (subject, from_email, to))

0 comments on commit 0a6b715

Please sign in to comment.