Changeset 1469 for pykota

Show
Ignore:
Timestamp:
05/11/04 10:26:27 (21 years ago)
Author:
jalet
Message:

Now catches connection problems to SMTP server

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/tool.py

    r1443 r1469  
    2222# 
    2323# $Log$ 
     24# Revision 1.85  2004/05/11 08:26:27  jalet 
     25# Now catches connection problems to SMTP server 
     26# 
    2427# Revision 1.84  2004/04/21 08:36:32  jalet 
    2528# Exports the PYKOTASTATUS environment variable when SIGTERM is received. 
     
    327330import locale 
    328331import signal 
     332import socket 
    329333 
    330334from mx import DateTime 
     
    468472        if "@" not in touser : 
    469473            touser = "%s@%s" % (touser, self.maildomain or self.smtpserver) 
    470         server = smtplib.SMTP(self.smtpserver) 
    471         try : 
    472             server.sendmail(adminmail, [touser], "From: %s\nTo: %s\n%s" % (adminmail, touser, fullmessage)) 
    473         except smtplib.SMTPException, answer :     
    474             for (k, v) in answer.recipients.items() : 
    475                 self.logger.log_message(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error") 
    476         server.quit() 
     474        try :     
     475            server = smtplib.SMTP(self.smtpserver) 
     476        except socket.error, msg :     
     477            self.logger.log_message(_("Impossible to connect to SMTP server : %s") % msg, "error") 
     478        else : 
     479            try : 
     480                server.sendmail(adminmail, [touser], "From: %s\nTo: %s\n%s" % (adminmail, touser, fullmessage)) 
     481            except smtplib.SMTPException, answer :     
     482                for (k, v) in answer.recipients.items() : 
     483                    self.logger.log_message(_("Impossible to send mail to %s, error %s : %s") % (k, v[0], v[1]), "error") 
     484            server.quit() 
    477485         
    478486    def sendMessageToUser(self, admin, adminmail, user, subject, message) :