Odoo Help


How to automatically attach a file to all outgoing email?

on 6/19/13, 6:27 AM 7,569 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.)

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):

  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?

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()))

on 6/24/13, 8:20 PM

Very nicely done!

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

Omal Bastin

--Omal Bastin--

| 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;)

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

on 6/19/13, 8:06 PM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


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