콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
19308 화면

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

아바타
취소
베스트 답변

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

베스트 답변

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

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?

관련 게시물 답글 화면 활동
1
4월 25
4311
0
9월 17
2793
0
2월 25
1432
4
8월 24
8751
1
12월 23
3753