Skip to Content
Menu
This question has been flagged
3 Replies
18465 Views

How can i add an image to my email signature in openerp 7?

Avatar
Discard
Best Answer

Hi,

you can add an inline-Image:

<img src="data:image/png;base64,${object.company_id.logo}" style="width: 250px;" />

But as the inline-Image gets removed by html-cleaner, you will have to use the following patch:

--- tools/mail.py.orig 2013-08-02 18:32:20.096029323 +0200 +++ tools/mail.py 2013-08-02 18:34:12.324027176 +0200 @@ -55,6 +55,9 @@

     # some corner cases make the parser crash (such as <SCRIPT/XSS SRC=\"\"></SCRIPT> in test_mail)
     try:
+       # thanks to stackoverflow questions/15386605/lxml-cleaner-to-ignore-base64-image for solution
+       cleaner_pattern = '\s*(?:javascript:|jscript:|livescript:|vbscript:|data:[^(?:image/.+;base64)]+|about:|mocha:)'
+       clean._javascript_scheme_re = re.compile(cleaner_pattern, re.I)
         cleaner = clean.Cleaner(page_structure=True, style=False, safe_attrs_only=False, forms=False, kill_tags=tags_to_kill, remove_tags=tags_to_remove)
         cleaned = cleaner.clean_html(src)
     except TypeError, e:

Hope this helps.

Best regards,

Reinhard

Avatar
Discard

I done as you told, but no use????please can u explain in brief......

Best Answer

You can add attribute sanitize=False to signature field at openerp/addons/base/res/res_users.py file

 'signature': fields.html('Signature', sanitize=False)


Unfortunally not all email clients shows base64 encoded images. Such images should be replaces by attachments. You can overwrite build_email function of a ir.mail_server model:

class ir_mail_server(models Mode): 
_inherit
= "ir.mail_server" def build_email(self, email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False, attachments=None, message_id=None, references=None, object_id=False, subtype='plain', headers=None, body_alternative=None, subtype_alternative='plain'): """ copy-pasted from openerp/addons/base/ir/ir_mail_server.py::build_email """ ftemplate = '__image-%s__' fcounter = 0 attachments = attachments or [] pattern = re.compile(r'"data:image/png;base64,[^"]*"') pos = 0 new_body = '' while True: match = pattern.search(body, pos) if not match: break s = match.start() e = match.end() data = body[s+len('"data:image/png;base64,'):e-1] new_body += body[pos:s] fname = ftemplate % fcounter fcounter += 1 attachments.append( (fname, base64.b64decode(data)) ) new_body += '"cid:%s"' % fname pos = e new_body += body[pos:] body = new_body //...


Or you can just try my module res_users_signature which also add signature templates feature.

Avatar
Discard

Hi Ivan, I installed your modul. But when I use the same example like you with . I don't get an Image. I only get the base64 encoded Image and it don't show something else then the base64 string. Any idea? Thanks

Hi Ivan, I installed your modul. But when I use the same example like you with ${user.company_id.logo_web}. I don't get an Image. I only get the base64 encoded Image and it don't show something else then the base64 string. Any idea? Thanks

Hello @IvanYelizariev Thanks for reply The real patch that applied was: https://gist.github.com/moylop260/c9ed3703f3ad05133c5c10974c907a0a really?

Related Posts Replies Views Activity
1
Apr 25
3364
0
Sep 17
2269
0
Feb 25
351
4
Aug 24
7893
1
Dec 23
1958