Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
17188 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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?

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

Автор

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

Very nicely done!

Найкраща відповідь

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

Автор

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

Related Posts Відповіді Переглядів Дія
0
груд. 16
3097
0
лют. 16
3013
1
бер. 15
4585
0
бер. 15
3534
0
лют. 25
783