source: TI03-DataExtractor/trunk/pydxs/mailUser.py @ 794

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/trunk/pydxs/mailUser.py@794
Revision 794, 1.5 KB checked in by astephen, 13 years ago (diff)

Unstable but latest version with multi-variable support and split hooks
for CDML and CSML.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6mailUser.py
7===========
8
9Holds the MailUser class used to contact the user via e-mail to
10inform them of an event.
11
12"""
13
14# Import python standard library modules
15import smtplib
16
17# Import package module global variables
18from serverConfig import LOCAL_MAIL_HOST, ADMIN_MAIL_ADDRESS, PACKAGE_NAME
19
20class MailUser:
21    """
22    MailUser class - sets up a mail message and sends.
23    """
24
25    def __init__(self, userEmail, subject):
26        """
27        __init__ method - takes the recipients e-mail address and mail subject
28        as arguments and then sets up the instance variables to be used by the
29        sendMail method.
30        """
31        self.email=userEmail
32        self.subject=subject
33        self.mailserver=smtplib.SMTP(LOCAL_MAIL_HOST)
34        self.mailserver.set_debuglevel(1)
35       
36    def sendMail(self, message):
37        """
38        sendMail method - takes the message content, compiles the full message
39        and mails to user.
40        """
41        fromaddr=ADMIN_MAIL_ADDRESS
42        mail_content="""To: %s
43From: %s
44Subject: %s
45This message has been automatically generated by the %s\n
46%s""" % (self.email, fromaddr, self.subject, PACKAGE_NAME, message)
47
48        self.mailserver.sendmail(fromaddr, self.email, mail_content)
49        self.mailserver.quit()
Note: See TracBrowser for help on using the repository browser.