[MERGE] From Christophe Chauvet (Sylëam)

bzr revid: stephane@tinyerp.com-20090302140135-np2ucu001u3o77hy
This commit is contained in:
Stephane Wirtel 2009-03-02 15:01:35 +01:00
commit 7811b928fd
1 changed files with 17 additions and 2 deletions

View File

@ -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."""
print 'sending', email_from, email_to, subject, body
import smtplib
@ -317,6 +318,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 +335,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 +345,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())