[Zope-Checkins] SVN: Zope/trunk/ MailHost now uses zope.sendmail in
order to integrate
Andreas Jung
andreas at andreas-jung.com
Sun Aug 19 03:24:25 EDT 2007
Log message for revision 78982:
MailHost now uses zope.sendmail in order to integrate
with Zope transactions
Changed:
U Zope/trunk/doc/CHANGES.txt
U Zope/trunk/lib/python/Products/MailHost/MailHost.py
-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt 2007-08-19 06:38:48 UTC (rev 78981)
+++ Zope/trunk/doc/CHANGES.txt 2007-08-19 07:24:24 UTC (rev 78982)
@@ -64,6 +64,10 @@
Features added
+ - MailHost: now uses zope.sendmail for delivering the mail providing
+ integration with the Zope transaction system (avoids sending dupe
+ emails in case of conflict errors)
+
- integrated ZODB 3.8
- integrated Zope 3.4
Modified: Zope/trunk/lib/python/Products/MailHost/MailHost.py
===================================================================
--- Zope/trunk/lib/python/Products/MailHost/MailHost.py 2007-08-19 06:38:48 UTC (rev 78981)
+++ Zope/trunk/lib/python/Products/MailHost/MailHost.py 2007-08-19 07:24:24 UTC (rev 78982)
@@ -18,7 +18,6 @@
import mimetools
import rfc822
from cStringIO import StringIO
-from smtplib import SMTP
import Acquisition
import OFS.SimpleItem
@@ -29,16 +28,16 @@
from AccessControl.Role import RoleManager
from Globals import Persistent, DTMLFile, InitializeClass
from DateTime import DateTime
+
from zope.interface import implements
+from zope.sendmail.mailer import SMTPMailer
+from zope.sendmail.delivery import DirectMailDelivery
from interfaces import IMailHost
-
class MailHostError(Exception):
-
pass
-
manage_addMailHostForm=DTMLFile('dtml/addMailHost_form', globals())
def manage_addMailHost( self, id, title='', smtp_host='localhost'
, localhost='localhost', smtp_port=25
@@ -54,9 +53,8 @@
class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
+ """a mailhost...?"""
- 'a mailhost...?'
-
implements(IMailHost)
meta_type='Mail Host'
@@ -156,22 +154,24 @@
self._send( mfrom, mto, body )
security.declarePrivate('_send')
- def _send( self, mfrom, mto, messageText ):
+ def _send(self, mfrom, mto, messageText):
""" Send the message """
- smtpserver = SMTP(self.smtp_host, int(self.smtp_port) )
- if self.smtp_uid:
- smtpserver.login(self.smtp_uid, self.smtp_pwd)
- smtpserver.sendmail( mfrom, mto, messageText )
- smtpserver.quit()
+ mailer = SMTPMailer(self.smtp_host,
+ int(self.smtp_port),
+ self.smtp_uid or None,
+ self.smtp_pwd or None
+ )
+ delivery = DirectMailDelivery(mailer)
+ delivery.send(mfrom, mto, messageText)
+
InitializeClass(MailBase)
class MailHost(Persistent, MailBase):
+ """persistent version"""
- "persistent version"
-
def _encode(body, encode=None):
if encode is None:
return body
More information about the Zope-Checkins
mailing list