Ticket #5081: issue_5081.patch

File issue_5081.patch, 1.8 KB (added by jsandoval, 9 years ago)
  • mediagoblin/tools/mail.py

    From 8c5349ec56d877de74d7aa8c62565bddcaa593b2 Mon Sep 17 00:00:00 2001
    From: jsandoval <jsandoval@utp.edu.co>
    Date: Tue, 22 Mar 2016 20:05:26 -0400
    Subject: [PATCH] Fix #5081 - Unhelpful SMTP error
    
    ---
     mediagoblin/tools/mail.py | 23 +++++++++++++++++------
     1 file changed, 17 insertions(+), 6 deletions(-)
    
    diff --git a/mediagoblin/tools/mail.py b/mediagoblin/tools/mail.py
    index 74e59fb..a290879 100644
    a b def send_email(from_addr, to_addrs, subject, message_body):  
    101101        else:
    102102            smtp_init = smtplib.SMTP
    103103
    104         mhost = smtp_init(
    105             mg_globals.app_config['email_smtp_host'],
    106             mg_globals.app_config['email_smtp_port'])
    107 
     104        try:
     105            mhost = smtp_init(
     106                mg_globals.app_config['email_smtp_host'],
     107                mg_globals.app_config['email_smtp_port'])
     108        except socket.error:
     109            print("Couldn't contact mail server on <{host}>:<{port}>".format(
     110                host=mg_globals.app_config['email_smtp_host'],
     111                port=mg_globals.app_config['email_smtp_port']))
     112            return
     113           
    108114        # SMTP.__init__ Issues SMTP.connect implicitly if host
    109115        if not mg_globals.app_config['email_smtp_host']:  # e.g. host = ''
    110             mhost.connect()  # We SMTP.connect explicitly
    111 
     116            try:
     117                mhost.connect()  # We SMTP.connect explicitly
     118            except socket.error:
     119                print("Couldn't contact mail server on <{host}>:<{port}>".format(
     120                    host=mg_globals.app_config['email_smtp_host'],
     121                    port=mg_globals.app_config['email_smtp_port']))
     122                return
    112123        try:
    113124            mhost.starttls()
    114125        except smtplib.SMTPException: