I'm testing to get my python script to still run if the smtp server it uses went down. I have a local mail server im testing this with. The issue is when testing it, i get a large spew of text. It checks all its libraries and such, untill its get stuck at socket.py and the line says: raise error, msg.
The next line is: error: [Errno 111] Connection refused. Then after some location stuff, it says DeprecationWarning: BaseException has been deprecated as of Python 2.6. Then it has some more location stuff, and finishes with return apply(func, args)
Here is my function:
def email(): global mssg session = smtplib.SMTP(smtpserver) if authrequired: session.login(smtpuser, smtpass) try: session.sendmail(SENDER, RECIPIENTS, mssg) session.quit() except: raise error logit('server down') return
Ive done some research and it seems i need to make a class in the script such as:
class MyError(Exception): def __init__ (self, value): self.value = value def __str__(self): return repr(self.value)
But im not sure if i have to swap anything here. For example, do i put 'error: [Errno 111] Connection refused' in the (Exception). Or if thats fine the way it is, how do i go about calling it in my function?