[Zope-Checkins] CVS: Zope/lib/python/Products/MailHost - MailHost.py:1.68
Jens Vagelpohl
jens@zope.com
Mon, 14 Jan 2002 23:45:14 -0500
Update of /cvs-repository/Zope/lib/python/Products/MailHost
In directory cvs.zope.org:/tmp/cvs-serv18168
Modified Files:
MailHost.py
Log Message:
Factor out the actual sending of mail into a separate method
=== Zope/lib/python/Products/MailHost/MailHost.py 1.67 => 1.68 ===
self.smtp_port = str( smtp_port )
+
# staying for now... (backwards compatibility)
def _init(self, smtp_host, smtp_port):
self.smtp_host=smtp_host
self.smtp_port=smtp_port
+
security.declareProtected( 'Change configuration', 'manage_makeChanges' )
def manage_makeChanges(self,title,smtp_host,smtp_port, REQUEST=None):
'make the changes'
@@ -94,6 +96,7 @@
, manage_tabs_message=msg
)
+
security.declareProtected( use_mailhost_services, 'sendTemplate' )
def sendTemplate(trueself, self, messageTemplate,
statusTemplate=None, mto=None, mfrom=None,
@@ -109,8 +112,8 @@
if not headers.has_key(requiredHeader):
raise MailHostError,"Message missing SMTP Header '%s'"\
% requiredHeader
- mailserver = SMTP(trueself.smtp_host, trueself.smtp_port)
- mailserver.sendmail(headers['from'], headers['to'], messageText)
+
+ self._send( headers, messageText )
if not statusTemplate: return "SEND OK"
@@ -120,6 +123,7 @@
except:
return "SEND OK"
+
security.declareProtected( use_mailhost_services, 'send' )
def send(self, messageText, mto=None, mfrom=None, subject=None,
encode=None):
@@ -148,8 +152,9 @@
raise MailHostError,"Message missing SMTP Header '%s'"\
% requiredHeader
messageText=_encode(messageText, encode)
- smtpserver = SMTP(self.smtp_host, self.smtp_port)
- smtpserver.sendmail(headers['from'],headers['to'], messageText)
+
+ self._send( headers, messageText )
+
security.declareProtected( use_mailhost_services, 'scheduledSend' )
def scheduledSend(self, messageText, mto=None, mfrom=None, subject=None,
@@ -175,15 +180,27 @@
raise MailHostError,"Message missing SMTP Header '%s'"\
% requiredHeader
messageText=_encode(messageText, encode)
- smtpserver = SMTP(self.smtp_host, self.smtp_port)
- smtpserver.sendmail(headers['from'], headers['to'], messageText)
+
+ self._send( headers, messageText )
+
security.declareProtected( use_mailhost_services, 'simple_send' )
def simple_send(self, mto, mfrom, subject, body):
body="from: %s\nto: %s\nsubject: %s\n\n%s" % (
mfrom, mto, subject, body)
- mailserver = SMTP(self.smtp_host, self.smtp_port)
- mailserver.sendmail(mfrom, mto, body)
+ headers = {}
+ headers['from'] = mfrom
+ headers['to'] = mto
+
+ self._send( headers, body )
+
+
+ security.declarePrivate( '_send' )
+ def _send( self, headers, body ):
+ """ Send the message """
+ smtpserver = SMTP( self.smtp_host, self.smtp_port )
+ smtpserver.sendmail( headers['from'], headers['to'], body )
+ smtpserver.quit()
InitializeClass( MailBase )