Smtplib and exceptions- why it does NOT work

A printers at sendme.cz
Mon May 20 16:40:14 EDT 2002


Hi,
How can I get response from Smtplib?
For example I have 

class SMTPM:
    def sendMail(self):
        import smtplib
        s11 = smtplib.SMTP('smtp.sendme.cz')
        Response=s11.sendmail('a at NonExistingDomain1.com',"printers at sendme.cz","TEST")
        print Response
A=SMTPM()
A.sendMail()

When I start the class I will get the following exception:

SMTPSenderRefused: (501, '5.1.8 <a at NonExistingDomain1.com>... Domain of sender address a at NonExistingDomain1.com does not exist', 'a at NonExistingDomain1.com')
and execution stops.
I,however, would like to print only
(501, '5.1.8 <a at NonExistingDomain1.com>... Domain of sender address a at NonExistingDomain1.com does not exist', 'a at NonExistingDomain1.com')
without stopping execution. 

So I handled that exception and changed the class like this

class SMTPM:
    
    def sendMail(self):
        import smtplib
        self.s11 = smtplib.SMTP('smtp.sendme.cz')
        
        try: 
            Response=self.s11.sendmail('a at NonExistingDomain.com',"printers at sendme.cz","TEST")
        except(smtplib.SMTPRecipientsRefused,smtplib.SMTPSenderRefused ):
            print "Response ",Response
A=SMTPM()
A.sendMail()

But it does not work.
Can anybody please explain to me why?
thanks
Ladislav







More information about the Python-list mailing list