Added SMTP configuration options
authorJoar Wandborg <git@wandborg.com>
Sat, 6 Aug 2011 23:22:31 +0000 (01:22 +0200)
committerJoar Wandborg <git@wandborg.com>
Sat, 6 Aug 2011 23:22:31 +0000 (01:22 +0200)
mediagoblin/config_spec.ini
mediagoblin/util.py

index bbc1f7d62545a292112fcf3487181a8d6002d24b..bc6f00d9ef916e99a8fb3a7f632e196724580173 100644 (file)
@@ -20,6 +20,10 @@ 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_port = integer(default=25)
+email_smtp_user = string(default=None)
+email_smtp_pass = string(default=None)
 
 # Set to false to disable registrations
 allow_registration = boolean(default=True)
index 5880f85665b9f81e96d0ddfe8dc071b3d08bdedd..6dced54e6e1e9fecf94c0199eca1c2c483dfa317 100644 (file)
@@ -240,6 +240,9 @@ class FakeMhost(object):
     def connect(self):
         pass
 
+    def login(self):
+        pass
+
     def sendmail(self, from_addr, to_addrs, message):
         EMAIL_TEST_MBOX_INBOX.append(
             {'from': from_addr,
@@ -267,13 +270,20 @@ def send_email(from_addr, to_addrs, subject, message_body):
      - subject: subject of the email
      - message_body: email body text
     """
-    # TODO: make a mock mhost if testing is enabled
     if TESTS_ENABLED or mg_globals.app_config['email_debug_mode']:
         mhost = FakeMhost()
     elif not mg_globals.app_config['email_debug_mode']:
-        mhost = smtplib.SMTP()
-
-    mhost.connect()
+        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.login(
+            mg_globals.app_config['email_smtp_user'],
+            mg_globals.app_config['email_smtp_pass'])
 
     message = MIMEText(message_body.encode('utf-8'), 'plain', 'utf-8')
     message['Subject'] = subject