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 ...@@ -64,6 +64,10 @@ Zope Changes
Features added 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 ZODB 3.8
- integrated Zope 3.4 - integrated Zope 3.4
......
...@@ -18,7 +18,6 @@ $Id$ ...@@ -18,7 +18,6 @@ $Id$
import mimetools import mimetools
import rfc822 import rfc822
from cStringIO import StringIO from cStringIO import StringIO
from smtplib import SMTP
import Acquisition import Acquisition
import OFS.SimpleItem import OFS.SimpleItem
...@@ -29,16 +28,16 @@ from AccessControl.Permissions import view_management_screens ...@@ -29,16 +28,16 @@ from AccessControl.Permissions import view_management_screens
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
from Globals import Persistent, DTMLFile, InitializeClass from Globals import Persistent, DTMLFile, InitializeClass
from DateTime import DateTime from DateTime import DateTime
from zope.interface import implements from zope.interface import implements
from zope.sendmail.mailer import SMTPMailer
from zope.sendmail.delivery import DirectMailDelivery
from interfaces import IMailHost from interfaces import IMailHost
class MailHostError(Exception): class MailHostError(Exception):
pass pass
manage_addMailHostForm=DTMLFile('dtml/addMailHost_form', globals()) manage_addMailHostForm=DTMLFile('dtml/addMailHost_form', globals())
def manage_addMailHost( self, id, title='', smtp_host='localhost' def manage_addMailHost( self, id, title='', smtp_host='localhost'
, localhost='localhost', smtp_port=25 , localhost='localhost', smtp_port=25
...@@ -54,8 +53,7 @@ add = manage_addMailHost ...@@ -54,8 +53,7 @@ add = manage_addMailHost
class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
"""a mailhost...?"""
'a mailhost...?'
implements(IMailHost) implements(IMailHost)
...@@ -156,20 +154,22 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -156,20 +154,22 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
self._send( mfrom, mto, body ) self._send( mfrom, mto, body )
security.declarePrivate('_send') security.declarePrivate('_send')
def _send( self, mfrom, mto, messageText ): def _send(self, mfrom, mto, messageText):
""" Send the message """ """ Send the message """
smtpserver = SMTP(self.smtp_host, int(self.smtp_port) )
if self.smtp_uid: mailer = SMTPMailer(self.smtp_host,
smtpserver.login(self.smtp_uid, self.smtp_pwd) int(self.smtp_port),
smtpserver.sendmail( mfrom, mto, messageText ) self.smtp_uid or None,
smtpserver.quit() self.smtp_pwd or None
)
delivery = DirectMailDelivery(mailer)
delivery.send(mfrom, mto, messageText)
InitializeClass(MailBase) InitializeClass(MailBase)
class MailHost(Persistent, MailBase): class MailHost(Persistent, MailBase):
"""persistent version"""
"persistent version"
def _encode(body, encode=None): 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