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.

1

How to automatically attach a file to all outgoing email?

By
Martin
on 6/19/13, 6:27 AM 4,341 views

In some legislations it is obligatory, to send certain company information with every business email, such as the tax number etc. Because having this long stuff in the signature is ugly, I prefer to attach a vcard ("vcf") file with all emails. This can be easily ignored by most and easily used by some.

How can I attach a file to every outgoing email? It is OK, if the file is always the same for all users of the same company. (My setup is one-company, btw.)

1
Shaun Dawson
On 6/19/13, 8:23 PM

One way that I can think of to accomplish what you are after is to create a module which defines a class that inherits from mail.mail.

You can override the send() function to first add your attachment to the mail message, and then call the superclass' send() function. That will give you exactly what you need, and probably configurability besides.

class autoattach_mail(osv.osv):
  _name='mail.mail'
  _inherit='mail.mail'

  def send(self, cr, uid, ids, auto_commit=False, recipient_ids=None, context=None):

    #TODO: add your attachment to each mail message in ids

    return super(autoattach_mail, self).send(cr, uid, ids, auto_commit=auto_commit, recipient_ids=recipient_ids, context=context)

I will definetely try this. I wonder, how I would make OpenERP use my derived class instead of the base class?

Martin
on 6/20/13, 7:45 AM

It should do so automatically, if you set _name to the same thing as _inherit. You'll need to update the affected modules also, so when you run the server again, run it with "--update all".

Shaun Dawson
on 6/20/13, 12:18 PM

It took some time for me, to get through the details, but now it works. I copied the complete send() method, and just added the attachment: with open("mycompany.vcf") as f: attachments.append(("mycompany.vcf", f.read()))

Martin
on 6/24/13, 8:20 PM

Very nicely done!

Shaun Dawson
on 6/24/13, 8:33 PM
0

Omal Bastin

--Omal Bastin--
1146
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 6/19/13, 12:22 PM

Create a email template. In the advanced tab, there you can easily attach attachments. Then select this email template for sending mails

This works indeed, but all the support staff has still to remember to use the template with every outgoing email. It is just one click to use the template, but in my experience in most cases it will not be done. The question remains how to do this automatically. (Nearby, I could not find how to set the MIME type of the attachment. It should be Content-Type: text/x-vcard; charset=utf-8;)

Martin
on 6/19/13, 7:53 PM

Another (minor) problem with this approach is, that the VCard is visible in every comment sent out, taking a lot of screen real estate by default. One can probably solve this with a little bit of CSS, but still...

Martin
on 6/19/13, 8:06 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

1 follower(s)

Stats

Asked: 6/19/13, 6:27 AM
Seen: 4341 times
Last updated: 9/19/15, 3:03 PM