From c819aa1b7eba072bce4fe483cbb07277a15648f0 Mon Sep 17 00:00:00 2001 From: ced <> Date: Wed, 11 Jul 2007 15:10:16 +0000 Subject: [PATCH] kernel: add user/password authentification for sending email bzr revid: ced-06bf358e04977b27a081152360c1febf50d0c410 --- bin/tools/config.py | 8 ++++++-- bin/tools/misc.py | 6 ++++-- man/terp_serverrc.5 | 12 +++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/bin/tools/config.py b/bin/tools/config.py index 33ef69d05b8..213e8b0608b 100644 --- a/bin/tools/config.py +++ b/bin/tools/config.py @@ -62,6 +62,8 @@ class configmanager(object): 'logfile': None, 'secure': False, 'smtp_server': 'localhost', + 'smtp_user': False, + 'smtp_password': False, 'stop_after_init': False, # this will stop the server after initialization 'price_accuracy': 2, } @@ -88,7 +90,9 @@ class configmanager(object): parser.add_option("--stop-after-init", action="store_true", dest="stop_after_init", default=False, help="stop the server after it initializes") parser.add_option('--debug', dest='debug_mode', action='store_true', default=False, help='enable debug mode') parser.add_option("-S", "--secure", dest="secure", action="store_true", help="launch server over https instead of http", default=False) - parser.add_option('--smtp', dest='smtp_server', default='', help='specify the SMTP server for sending mail') + parser.add_option('--smtp', dest='smtp_server', default='', help='specify the SMTP server for sending email') + 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') group = optparse.OptionGroup(parser, "Modules related options") @@ -141,7 +145,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', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn'): + 'db_port', 'logfile', 'pidfile', 'secure', 'smtp_server', 'smtp_user', 'smtp_password', 'price_accuracy', 'netinterface', 'netport', 'db_maxconn'): if getattr(opt, arg): self.options[arg] = getattr(opt, arg) diff --git a/bin/tools/misc.py b/bin/tools/misc.py index 61912565ea9..09ebf5f9210 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -211,6 +211,8 @@ def email_send(email_from, email_to, subject, body, email_cc=[], email_bcc=[], o msg['Date'] = formatdate(localtime=True) try: s = smtplib.SMTP() + if config['smtp_user'] or config['smtp_password']: + s.login(config['smtp_user'], config['smtp_password']) s.connect(config['smtp_server']) s.sendmail(email_from, email_to + email_cc + email_bcc, msg.as_string()) s.quit() @@ -255,6 +257,8 @@ def email_send_attach(email_from, email_to, subject, body, email_cc=[], email_bc msg.attach(part) try: s = smtplib.SMTP() + if config['smtp_user'] or config['smtp_password']: + s.login(config['smtp_user'], config['smtp_password']) s.connect(config['smtp_server']) s.sendmail(email_from, email_to + email_cc + email_bcc, msg.as_string()) s.quit() @@ -270,9 +274,7 @@ def email_send_attach(email_from, email_to, subject, body, email_cc=[], email_bc def sms_send(user, password, api_id, text, to): import urllib params = urllib.urlencode({'user': user, 'password': password, 'api_id': api_id, 'text': text, 'to':to}) - #print "http://api.clickatell.com/http/sendmsg", params #f = urllib.urlopen("http://api.clickatell.com/http/sendmsg", params) - print "http://196.7.150.220/http/sendmsg", params f = urllib.urlopen("http://196.7.150.220/http/sendmsg", params) print f.read() return True diff --git a/man/terp_serverrc.5 b/man/terp_serverrc.5 index 770ba38df1a..9959509f4d0 100644 --- a/man/terp_serverrc.5 +++ b/man/terp_serverrc.5 @@ -55,10 +55,20 @@ Launch server over https instead of http. (default False) .TP .IR smtp_server -Specify the SMTP server for sending mail. +Specify the SMTP server for sending email. .br (default localhost) .TP +.IR smtp_user +Specify the SMTP user for sending email. +.br +(default False) +.TP +.IR smtp_password +Specify the SMTP password for sending email. +.br +(default False) +.TP .IR db_name Specify the database name. .br