Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

How to insert image to email signature?

By
Erik Bruder
on 7/15/13, 9:47 AM 6,003 views

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

1

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

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

venugopal voraganti
on 2/13/14, 5:42 AM
0
Ivan Yelizariev
On 3/17/15, 5:19 PM

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.

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

Dairidi
on 6/25/15, 8:50 AM

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

Dairidi
on 6/25/15, 8:53 AM

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

Vauxoo S.A. de C.V., Moisés Augusto López Calderón
on 5/27/16, 7:11 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 7/15/13, 9:47 AM
Seen: 6003 times
Last updated: 3/21/15, 7:03 AM