I have some suggested changes to /WebKit/ExceptionHandler.py that fix problems I recently encountered while sending out email messages for servlet tracebacks.
The problems started when my ISP changed the requirements for sending out mail via smtp. They went from no login required to a pop3 login required -- logging on to pop3 seems to allow emails to be sent via smtp for the next hour. The example below shows an attempt to initiate a connection without a pop3 login (this is a local cable company so an indirect connection will probably result in different errors). ''' >>> import smtplib >>> server = smtplib.SMTP('smtp.coxmail.com',25) Traceback (most recent call last): File "<pyshell#41>", line 1, in <module> server = smtplib.SMTP('smtp.coxmail.com',25) File "c:\Python25\lib\smtplib.py", line 246, in __init__ raise SMTPConnectError(code, msg) SMTPConnectError: (421, 'Sorry, you must log in before using this server.') ''' While trying to figure out that problem, I tried using google mail. But I found out that gmail requires a starttls() call before login. Also, gmail and the Python smtplib seem to be presently incompatible with quit(). Replacing the server.noop() with a login and sendmail in the example below will get the user logged in and the message sent OK, but the same error will occur on the quit(). ''' >>> import smtplib >>> server = smtplib.SMTP('smtp.gmail.com',25) >>> server.ehlo() (250, 'mx.google.com at your service, [68.98.218.211]\nSIZE 28311552\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES') >>> server.starttls() (220, '2.0.0 Ready to start TLS') >>> server.ehlo() (250, 'mx.google.com at your service, [68.98.218.211]\nSIZE 28311552\n8BITMIME\nAUTH LOGIN PLAIN\nENHANCEDSTATUSCODES') >>> server.noop() (250, '2.0.0 OK') >>> server.quit() Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> server.quit() File "c:\Python25\lib\smtplib.py", line 716, in quit self.docmd("quit") File "c:\Python25\lib\smtplib.py", line 378, in docmd return self.getreply() File "c:\Python25\lib\smtplib.py", line 352, in getreply line = self.file.readline() File "c:\Python25\lib\smtplib.py", line 160, in readline chr = self.sslobj.read(1) sslerror: (1, 'error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number') ''' Finally, the existing code resulted in no response after my pop3-smtp failures and the user was left waiting for the browser to timeout. The changes I made to the emailException method follow. In Webware 9.4, this replaces everything after "# Send the message" on line 571 to the end of the method. This has only been tested with my ISP's curious pop3 login and gmail. The "self._res.flush()" could be better placed in the calling method. The "import poplib" should probably go at the top of the module with the other imports. ''' # Send the message self._res.flush() # do not make user wait for email settings = self.setting('ErrorEmailServer') # this setting can be: server, server:port, server:port:user:password,server:port:user:password:pop3server parts = settings.split(':', 4) server = user = password = pop3Server = None port = 25 try: # assign passed values, ignore the rest server = parts[0] port = int(parts[1]) user = parts[2] password = parts[3] pop3Server = parts[4] except: pass try: # if there is a failure, don't bother the user, fail silently if pop3Server: # some mail servers require login to pop3 rather than smtp import poplib pop3 = poplib.POP3(pop3Server) pop3.user(user) pop3.pass_(password) pop3.quit() server = smtplib.SMTP(server,port) elif password: # some mail servers require login to smtp server = smtplib.SMTP(server,port) server.ehlo() if server.has_extn('starttls'): # some servers require a secure login server.starttls() server.ehlo() server.login(user, password) else: # some mail servers do not require login server = smtplib.SMTP(server,port) # server.set_debuglevel(1) server.sendmail(headers['From'], headers['To'], message.getvalue()) server.quit() except: pass return ''' Roger Haase ____________________________________________________________________________________ Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games. http://sims.yahoo.com/ ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Webware-discuss mailing list Webware-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/webware-discuss