kernel: add user/password authentification for sending email

bzr revid: ced-06bf358e04977b27a081152360c1febf50d0c410
This commit is contained in:
ced 2007-07-11 15:10:16 +00:00
parent 4189a9db07
commit c819aa1b7e
3 changed files with 21 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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