Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add only as inline image #141

Open
naga293avoma opened this issue Jan 18, 2023 · 9 comments
Open

add only as inline image #141

naga293avoma opened this issue Jan 18, 2023 · 9 comments

Comments

@naga293avoma
Copy link

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

@fjsj
Copy link
Member

fjsj commented Jan 20, 2023

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.

@naga293avoma
Copy link
Author

@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.

@fjsj
Copy link
Member

fjsj commented Jan 23, 2023

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.

@naga293avoma
Copy link
Author

@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

@fjsj
Copy link
Member

fjsj commented Jan 23, 2023

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

@naga293avoma
Copy link
Author

@fjsj thank you

@naga293avoma
Copy link
Author

@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

@fjsj
Copy link
Member

fjsj commented Sep 18, 2023

@naga293avoma can you paste your full email sending code?

@naga293avoma
Copy link
Author

@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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants