Home > other >  Add Image in Email From field
Add Image in Email From field

Time:01-14

In odoo 13 i have a field example:

birthday_picture = fields.Image(string='Birthday Picture')

i want to add birthday_picture image to be added in email template also which i declared in xml, i have added <img> tag and added still the image is not reflecting below i have shared the line

<div>
    <img src="${'/birthday_picture.png=%s' % object.birthday_picture}" style="width: 60px; height: 60px"/><br/>
</div>

please let me know where i am doing wrong

CodePudding user response:

If birthday_picture must be dynamic (this means the same email template may render different images) you should consider using fields.Binary

fields.Binary stores a binary file in odoo filesystem and returns a base64 encoded string.

birthday_picture = fields.Binary(string='Birthday Picture')
<img src="${'data:image/png;base64,%s' % object.birthday_picture}" style="width: 60px; height: 60px"/>

In case birthday_picture is always the same (so it is static) best solution would be to create an ir.attachment, set it as public and render into src it's url

Another option would be to manually convert your file into base64 using an online tool and replace src value with the encoded string.

CodePudding user response:

Actually i have added this:

<p>
    <img src="/web/image/birthday.reminder/${object.id}/birthday_picture/"/>
</p>

which doesnot reflect the image in template but when i looked for undelivered email from techncal > email. by removing force_send from code i can see my image reflected on it.

however i already searched that the email doesnot support base64 images but there is a tweak to do it as well. here is the link which descried the tweak

  • Related