From c524722e98987bdf12667316ddbcf05568520c3d Mon Sep 17 00:00:00 2001 From: "mga@tinyerp.com" <> Date: Tue, 29 Jul 2008 12:58:04 +0530 Subject: [PATCH] config.py : add 2 more options to the server startup * --email-from : to have an globel email sending address * --smtp-ssl : if smtp server required ssl support ir_actions.py : upgrade email sending procedure misc.py: review email_send_attach procecure to use the new parameters to server bzr revid: mga@tinyerp.com-20080729072804-vfgm40ga3tty5kw1 --- bin/addons/base/ir/ir_actions.py | 8 ++++---- bin/tools/config.py | 5 ++++- bin/tools/misc.py | 5 ++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/addons/base/ir/ir_actions.py b/bin/addons/base/ir/ir_actions.py index e8ac28e97c4..dc403a15210 100644 --- a/bin/addons/base/ir/ir_actions.py +++ b/bin/addons/base/ir/ir_actions.py @@ -324,13 +324,13 @@ class actions_server(osv.osv): if 'action' in localdict: return localdict['action'] if action.state == 'email': - user = "%s@yahoo.co.in," % (config['smtp_user']) + user = config['email_from'] subject = action.name body = action.message - if tools.email_send_attach(user, action.address, subject, body) == True: - logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (user)) + if tools.email_send_attach(user, action.address, subject, body, debug=False) == True: + logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (action.address)) else: - logger.notifyChannel('email', netsvc.LOG_ERROR, 'Failed to send email to : %s' % (user)) + logger.notifyChannel('email', netsvc.LOG_ERROR, 'Failed to send email to : %s' % (action.address)) return False actions_server() diff --git a/bin/tools/config.py b/bin/tools/config.py index 5f48ecc2e57..f4a3674e67e 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -34,6 +34,7 @@ import netsvc,logging class configmanager(object): def __init__(self, fname=None): self.options = { + 'email_from':False, 'verbose': False, 'interface': '', # this will bind the server to all interfaces 'port': '8069', @@ -95,7 +96,9 @@ class configmanager(object): parser.add_option('--debug', dest='debug_mode', action='store_true', default=False, help='enable debug mode') parser.add_option("--assert-exit-level", dest='assert_exit_level', help="specify the level at which a failed assertion will stop the server " + str(assert_exit_levels)) parser.add_option("-S", "--secure", dest="secure", action="store_true", help="launch server over https instead of http", default=False) + parser.add_option('--email-from', dest='email_from', default='', help='specify the SMTP email address for sending email') parser.add_option('--smtp', dest='smtp_server', default='', help='specify the SMTP server for sending email') + parser.add_option('--smtp-ssl', dest='smtp_ssl', default='', help='specify the SMTP server support SSL or not') parser.add_option('--smtp-user', dest='smtp_user', default='', help='specify the SMTP username for sending email') parser.add_option('--smtp-password', dest='smtp_password', default='', help='specify the SMTP password for sending email') parser.add_option('--price_accuracy', dest='price_accuracy', default='2', help='specify the price accuracy') @@ -150,7 +153,7 @@ class configmanager(object): self.options['pidfile'] = False for arg in ('interface', 'port', 'db_name', 'db_user', 'db_password', 'db_host', - 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'commit_mode', 'addons_path'): + 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_ssl', 'email_from', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn', 'commit_mode', 'addons_path'): if getattr(opt, arg): self.options[arg] = getattr(opt, arg) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 4d8966ffc87..b19031dee89 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -352,7 +352,10 @@ def email_send_attach(email_from, email_to, subject, body, email_cc=None, email_ from email import Encoders msg = MIMEMultipart() - + + if not ssl: + ssl = config['smtp_ssl'] + msg['Subject'] = Header(subject.decode('utf8'), 'utf-8') msg['From'] = email_from del msg['Reply-To']