Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
SecureMailHost.mail.Mail Class Reference

List of all members.

Public Member Functions

def __init__
def setId
def getId
def incError
def getErrors
def send
def __str__
def __repr__
def info

Public Attributes

 mfrom
 mto
 message
 host
 port
 kwargs
 errors
 id

Detailed Description

A email object which knows how to send itself

mfrom     - mail from tag (only for SMTP server)
mto       - mail to tag (only for SMTP server)
message   - The message email.Message.Message based object
smtp_host - SMTP server address
smtp_port - SMTP server port
**kwargs  - additional keywords like userid, password and forceTLS

Definition at line 32 of file mail.py.


Constructor & Destructor Documentation

def SecureMailHost.mail.Mail.__init__ (   self,
  mfrom,
  mto,
  message,
  smtp_host = 'localhost',
  smtp_port = 25,
  kwargs 
)

Definition at line 45 of file mail.py.

00045 
00046                  **kwargs):
00047         self.mfrom = mfrom
00048         self.mto = mto
00049         # message must be email.Message.Message based
00050         assert(isinstance(message, email.Message.Message))
00051         # Add some important headers
00052         if not message.has_key('Date'):
00053             message['Date'] = DateTime().rfc822()
00054         if not message.has_key('X-Mailer'):
00055             message['X-Mailer'] = X_MAILER
00056         if not message.has_key('Message-Id'):
00057             fqdn = socket.getfqdn()
00058             message['Message-Id'] = email.Utils.make_msgid(fqdn)
00059 
00060         self.message = message
00061 
00062         self.host = smtp_host
00063         self.port = int(smtp_port)
00064 
00065         self.kwargs = kwargs
00066         self.errors = 0
00067         self.id = None


Member Function Documentation

Definition at line 138 of file mail.py.

00138 
00139     def __repr__(self):
00140         return '<%s (%s) at %s>' % (
00141             self.__class__.__name__, self.info(),
00142             id(self))

Here is the call graph for this function:

Definition at line 135 of file mail.py.

00135 
00136     def __str__(self):
00137         return self.message.as_string()

Get the error counter

Definition at line 83 of file mail.py.

00083 
00084     def getErrors(self):
00085         """Get the error counter
00086         """
00087         return self.errors

Get unique id

Definition at line 73 of file mail.py.

00073 
00074     def getId(self):
00075         """Get unique id
00076         """
00077         return self.id

Increase the error counter

Definition at line 78 of file mail.py.

00078 
00079     def incError(self):
00080         """Increase the error counter
00081         """
00082         self.errors+=1

Return status informations about the email

Definition at line 143 of file mail.py.

00143 
00144     def info(self):
00145         """Return status informations about the email
00146         """
00147         return ('From: %(from)s, To: %(to)s, Subject: %(subject)s '
00148                 '(s:%(size)d, e:%(errors)d)' % {
00149             'id' : self.getId(), 'errors' : self.errors,
00150             'from' : self.message['From'], 'to' : self.message['To'],
00151             'subject' : self.message['Subject'], 'size' : len(self.message)
00152             })

Here is the caller graph for this function:

def SecureMailHost.mail.Mail.send (   self,
  debug = False 
)
Send email to the SMTP server

Definition at line 88 of file mail.py.

00088 
00089     def send(self, debug=False):
00090         """Send email to the SMTP server
00091         """
00092         kw = self.kwargs
00093         userid   = kw.get('userid', None)
00094         password = kw.get('password', None)
00095         forceTLS = kw.get('forcetls', False)
00096         noTLS    = kw.get('notls', False)
00097         message  = self.message.as_string()
00098 
00099         # connect
00100         if not self.host:
00101             raise MailHostError('No mailserver has been configured')
00102 
00103         smtpserver = smtplib.SMTP(self.host, self.port)
00104         if debug:
00105             smtpserver.set_debuglevel(1)
00106 
00107         # Try EHLO first, then HELO.
00108         if not (200 <= smtpserver.ehlo()[0] <= 299):
00109             (code, resp) = smtpserver.helo()
00110             if not (200 <= code <= 299):
00111                 raise MailHostError('Host refused to talk to us: %s' % resp)
00112 
00113         # check for ssl encryption
00114         if smtpserver.has_extn('starttls') and ssl_support and not(noTLS):
00115             smtpserver.starttls()
00116             smtpserver.ehlo()
00117         elif forceTLS:
00118             if noTLS:
00119                 raise MailHostError('Configured not to try TLS '
00120                     'but it is required')
00121             else:
00122                 raise MailHostError('Host does NOT support StartTLS '
00123                     'but it is required')
00124         # login
00125         if smtpserver.does_esmtp:
00126             if userid:
00127                 smtpserver.login(userid, password)
00128         elif userid:
00129             #indicate error here to prevent inadvertent use of spam relay
00130             raise MailHostError('Host does NOT support ESMTP '
00131                                 'but username/password provided')
00132         # send and quit
00133         smtpserver.sendmail(self.mfrom, self.mto, message)
00134         smtpserver.quit()

def SecureMailHost.mail.Mail.setId (   self,
  id 
)
Set the unique id of the email

Definition at line 68 of file mail.py.

00068 
00069     def setId(self, id):
00070         """Set the unique id of the email
00071         """
00072         self.id = id

Here is the caller graph for this function:


Member Data Documentation

Definition at line 65 of file mail.py.

Definition at line 61 of file mail.py.

Definition at line 66 of file mail.py.

Definition at line 64 of file mail.py.

Definition at line 59 of file mail.py.

Definition at line 46 of file mail.py.

Definition at line 47 of file mail.py.

Definition at line 62 of file mail.py.


The documentation for this class was generated from the following file: