django-templated-email icon indicating copy to clipboard operation
django-templated-email copied to clipboard

add only as inline image

Open naga293avoma opened this issue 2 years ago • 9 comments

Images are also being attached in some email clients. Can we add them as only inline images

naga293avoma avatar Jan 18 '23 05:01 naga293avoma

Please show an example of how are you adding the images, but I think what you're seeing here is not really related to django-templated-email.

fjsj avatar Jan 20 '23 18:01 fjsj

@fjsj This is how I am reading the images.

        with open(path_to_img, 'rb') as image:
            image = image.read()
        inline_image = InlineImage(filename=image_name, content=image)

I tried with subtype=related also but no use.

Html snippet is attached below.

<div>
  <img class= child src="{{inline_image}}" style="vertical-align:text-bottom;display: inline;height:16px;min-height:16px;">
 <p class=child style="display: inline;margin-left:  12.25px;margin-top: 0px;font-family: 'Arial';font-style: normal;font-weight: 700;font-size: 16px;line-height: 24px;letter-spacing: 0.4px;color: #1B2733;">Inline  Image</p>
 </div>

Image is rendering inline properly but they are also being attached as attachments. Weird thing is not all mails being generated have attached images. It is inconsistent but all the mails have the same data and are being generated from same template.

naga293avoma avatar Jan 21 '23 07:01 naga293avoma

Check this: https://markvanlent.dev/2014/01/15/sending-emails-with-embedded-images-in-django/ Seems it depends on the multipart you're setting to your email. Not related to django-templated-email I guess.

fjsj avatar Jan 23 '23 12:01 fjsj

@fjsj I am using get_templated_email as mentioned in the documentation and it it is returning email with content-type:multipart/mixed. Any idea how to change email content-type

naga293avoma avatar Jan 23 '23 13:01 naga293avoma

get_templated_email returns an EmailMessage object. You can try: email_message.mixed_subtype = 'related' before calling send.

fjsj avatar Jan 23 '23 14:01 fjsj

@fjsj thank you

naga293avoma avatar Jan 23 '23 14:01 naga293avoma

@fjsj thanks for the info it worked but currently when I forward the emails inline images are not rendering and they are just being attchedas images. Do you have any context why can this happen

naga293avoma avatar Sep 18 '23 12:09 naga293avoma

@naga293avoma can you paste your full email sending code?

fjsj avatar Sep 18 '23 13:09 fjsj

@fjsj and we send these emails via ses

    def get_inline_image(path_to_img, image_name):
        with open(path_to_img, 'rb') as image:
            image = image.read()
        inline_image = InlineImage(filename=image_name, content=image)
        return inline_image
     def send_email():
             privacy=get_privacy()
            privacy_icon = EmailUtilsApi.get_inline_image(
                'apps/user/templates/templated_email/static/privacy_icon_500x500.png', 'privacy_icon.png')
              email = get_templated_mail(
            template_name='test_email',
            from_email=from_email,
            to=[user.email],
            context={
            'privacy':privacy,
            'privacy_icon':privacy_icon
            }
         email.mixed_subtype = 'related'
         email.send()
<div>
  <img class= child src="{{privacy_icon}}" style="vertical-align:text-bottom;display: inline;height:16px;min-height:16px;">
 <p class=child style="display: inline;margin-left:  12.25px;margin-top: 0px;font-family: 'Arial';font-style: normal;font-weight: 700;font-size: 16px;line-height: 24px;letter-spacing: 0.4px;color: #1B2733;">Privacy</p>
 </div>

naga293avoma avatar Sep 20 '23 08:09 naga293avoma