Commit 0e38c34a authored by Andreas Jung's avatar Andreas Jung

MailHost now uses zope.sendmail in order to integrate

with Zope transactions
parent c9f3c5ec
......@@ -64,6 +64,10 @@ Zope Changes
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
......
......@@ -18,7 +18,6 @@ $Id$
import mimetools
import rfc822
from cStringIO import StringIO
from smtplib import SMTP
import Acquisition
import OFS.SimpleItem
......@@ -29,16 +28,16 @@ from AccessControl.Permissions import view_management_screens
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,8 +53,7 @@ add = manage_addMailHost
class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
'a mailhost...?'
"""a mailhost...?"""
implements(IMailHost)
......@@ -156,20 +154,22 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment