source: TI03-DataExtractor/branches/old_stuff/dx/mailUser.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx/mailUser.py@793
Revision 793, 1.2 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"""
2mailUser.py
3===========
4
5Holds the MailUser class used to contact the user via e-mail to
6inform them of an event.
7
8"""
9
10# Import python standard library modules
11import smtplib
12
13# Import package module global variables
14from config import LOCAL_MAIL_HOST, ADMIN_MAIL_ADDRESS, PACKAGE_NAME
15
16class MailUser:
17    """
18    MailUser class - sets up a mail message and sends.
19    """
20
21    def __init__(self, userEmail, subject):
22        """
23        __init__ method - takes the recipients e-mail address and mail subject
24        as arguments and then sets up the instance variables to be used by the
25        sendMail method.
26        """
27        self.email=userEmail
28        self.subject=subject
29        self.mailserver=smtplib.SMTP(LOCAL_MAIL_HOST)
30        self.mailserver.set_debuglevel(1)
31       
32    def sendMail(self, message):
33        """
34        sendMail method - takes the message content, compiles the full message
35        and mails to user.
36        """
37        fromaddr=ADMIN_MAIL_ADDRESS
38        mail_content="""To: %s
39From: %s
40Subject: %s
41This message has been automatically generated by the %s\n
42%s""" % (self.email, fromaddr, self.subject, PACKAGE_NAME, message)
43
44        self.mailserver.sendmail(fromaddr, self.email, mail_content)
45        self.mailserver.quit()
Note: See TracBrowser for help on using the repository browser.