From 09cc1b4c5bd0b99f28b766afc1e7442411621571 Mon Sep 17 00:00:00 2001 From: Christophe Chauvet Date: Mon, 2 Mar 2009 16:54:56 +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-20090302155456-vsu5rjlg3r694m6q --- bin/tools/misc.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 5eee773f0f1..a67c1821f72 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -302,7 +302,8 @@ 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_headers=None): """Send an email.""" import smtplib from email.MIMEText import MIMEText @@ -316,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: @@ -330,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) @@ -338,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 key, value in x_headers.items(): + msg['X-OpenERP-%s' % key] = str(value) + if tinycrm: msg['Message-Id'] = "<%s-tinycrm-%s@%s>" % (time.time(), tinycrm, socket.gethostname())