From d71170ad0abea7768c425a6011816cd8cdadf9df Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 25 Aug 2011 19:38:13 +0200 Subject: [PATCH] Feature #489 - SMTP configuration options - Acts on feedback from cwebber. http://bugs.foocorp.net/issues/489#note-2 --- mediagoblin/config_spec.ini | 2 +- mediagoblin/util.py | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini index bc6f00d9..0bc7d6ad 100644 --- a/mediagoblin/config_spec.ini +++ b/mediagoblin/config_spec.ini @@ -20,7 +20,7 @@ direct_remote_path = string(default="/mgoblin_static/") # set to false to enable sending notices email_debug_mode = boolean(default=True) email_sender_address = string(default="notice@mediagoblin.example.org") -email_smtp_host = string(default=None) +email_smtp_host = string(default='') email_smtp_port = integer(default=25) email_smtp_user = string(default=None) email_smtp_pass = string(default=None) diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 6dced54e..60ba8800 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -237,10 +237,7 @@ class FakeMhost(object): Just a fake mail host so we can capture and test messages from send_email """ - def connect(self): - pass - - def login(self): + def login(self, *args, **kwargs): pass def sendmail(self, from_addr, to_addrs, message): @@ -273,14 +270,16 @@ def send_email(from_addr, to_addrs, subject, message_body): if TESTS_ENABLED or mg_globals.app_config['email_debug_mode']: mhost = FakeMhost() elif not mg_globals.app_config['email_debug_mode']: - if not mg_globals.app_config['email_smtp_host']: - mhost = smtplib.SMTP() - else: - mhost = smtplib.SMTP( - mg_globals.app_config['email_smtp_host'], - mg_globals.app_config['email_smtp_port']) - - if mg_globals.app_config['email_smtp_user']: + mhost = smtplib.SMTP( + mg_globals.app_config['email_smtp_host'], + mg_globals.app_config['email_smtp_port']) + + # SMTP.__init__ Issues SMTP.connect implicitly if host + if not mg_globals.app_config['email_smtp_host']: # e.g. host = '' + mhost.connect() # We SMTP.connect explicitly + + if mg_globals.app_config['email_smtp_user'] \ + or mg_globals.app_config['email_smtp_pass']: mhost.login( mg_globals.app_config['email_smtp_user'], mg_globals.app_config['email_smtp_pass']) -- 2.25.1