From 3ff49ccb09b6322aaae4b755b3e8c81a5e471580 Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Sat, 28 Feb 2009 14:53:40 +0100 Subject: [PATCH] [IMP] * Check if sender or default email in config file * Add X-Header (help filter on mail client) * Add dynamic X-Header on def method * Correct incoherent reply to when it exists bzr revid: christophe.chauvet@syleam.fr-20090228135340-02gydu6xc009tb1j --- bin/tools/misc.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 28f529a76b0..2aa1919cae0 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -302,7 +302,7 @@ def reverse_enumerate(l): #---------------------------------------------------------- # Emails #---------------------------------------------------------- -def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False, attach=None, tinycrm=False, ssl=False, debug=False, subtype='plain'): +def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False, attach=None, tinycrm=False, ssl=False, debug=False, subtype='plain', x_header={}): """Send an email.""" print 'sending', email_from, email_to, subject, body import smtplib @@ -317,6 +317,9 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non if not ssl: ssl = config.get('smtp_ssl', False) + if not email_from and not config['email_from']: + raise Exception("No Email sender by default, see config file") + if not email_cc: email_cc = [] if not email_bcc: @@ -331,7 +334,9 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non msg['From'] = email_from del msg['Reply-To'] if reply_to: - msg['Reply-To'] = msg['From']+', '+reply_to + msg['Reply-To'] = reply_to + else: + msg['Reply-To'] = msg['From'] msg['To'] = COMMASPACE.join(email_to) if email_cc: msg['Cc'] = COMMASPACE.join(email_cc) @@ -339,6 +344,15 @@ def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=Non msg['Bcc'] = COMMASPACE.join(email_bcc) msg['Date'] = formatdate(localtime=True) + # Add OpenERP Server information + msg['X-Generated-By'] = 'OpenERP (http://www.openerp.com)' + msg['X-OpenERP-Server-Host'] = socket.gethostname() + msg['X-OpenERP-Server-Version'] = release.version + + # Add dynamic X Header + for x in x_header.keys(): + msg['X-OpenERP-%s' % x] = str(x_header[x]) + if tinycrm: msg['Message-Id'] = "<%s-tinycrm-%s@%s>" % (time.time(), tinycrm, socket.gethostname())