add only as inline image
naga293avoma opened this issue · 9 comments
Images are also being attached in some email clients. Can we add them as only inline images
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 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.
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 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
get_templated_email
returns an EmailMessage
object. You can try: email_message.mixed_subtype = 'related'
before calling send
.
@fjsj thank you
@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 can you paste your full email sending code?
@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>