source: TI03-DataExtractor/branches/old_stuff/dx_badc/reportError.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx_badc/reportError.py@793
Revision 793, 1.5 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

  • Property svn:executable set to *
Line 
1"""
2reportError.py module
3=====================
4Function mailErrorTo() takes the error, module running,
5recipients and status of an error message and mails it
6accordingly.
7"""
8
9import smtplib
10
11def mailErrorTo(error, module, recipients, subject="", status="normal"):
12  server=smtplib.SMTP('localhost')
13  server.set_debuglevel(1)
14 
15  fromaddr="From: badc@rl.ac.uk"
16  toaddr=recipients
17 
18  message="To: %s\n" % toaddr
19  message=message+"From: %s\n" % fromaddr
20  message=message+"Subject: %s\n" % subject
21  message=message+"This is an automatic BADC error report:\n"
22  message=message+"=======================================\n\n"
23  message=message+"\nWithin module:\t"+module+"\n\n"
24  message=message+"\nError content:\t\n"+error
25   
26  server.sendmail(fromaddr, toaddr, message)
27  server.quit()
28 
29def mailInfoTo(info, module, recipients, subject="", status="normal"):
30  server=smtplib.SMTP('localhost')
31  server.set_debuglevel(1)
32 
33  fromaddr="From: badc@rl.ac.uk"
34  toaddr=recipients
35 
36  message="To: %s\n" % toaddr
37  message=message+"From: %s\n" % fromaddr
38  message=message+"Subject: %s\n" % subject
39  message=message+"This is an automatic BADC information report:\n"
40  message=message+"=============================================\n\n"
41  message=message+"\nWithin module:\t"+module+"\n\n"
42  message=message+"\nInformation content:\t\n"+info
43   
44  server.sendmail(fromaddr, toaddr, message)
45  server.quit()
46
47if __name__ == "__main__":
48  mailErrorTo("Bad programme", __name__, "a.stephens@rl.ac.uk")
Note: See TracBrowser for help on using the repository browser.