Catch SMTP exceptions when sending email notifications.

svn path=/plone.app.discussion/trunk/; revision=45199
This commit is contained in:
Timo Stollenwerk 2010-11-04 15:56:12 +00:00
parent 13e9d54793
commit cbd2edf932
2 changed files with 56 additions and 18 deletions

View File

@ -1,6 +1,13 @@
Changelog Changelog
========= =========
1.0RC1 (unreleased)
-------------------
- Catch SMTP exceptions when sending email notifications.
[timo]
1.0b12 (2010-11-04) 1.0b12 (2010-11-04)
------------------- -------------------

View File

@ -1,8 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""The default comment class and factory. """The default comment class and factory.
""" """
import logging
from datetime import datetime from datetime import datetime
from smtplib import SMTPException
from zope.annotation.interfaces import IAnnotatable from zope.annotation.interfaces import IAnnotatable
from zope.component.factory import Factory from zope.component.factory import Factory
@ -52,6 +57,8 @@ MAIL_NOTIFICATION_MESSAGE = _(u"mail_notification_message",
default=u"A comment on '${title}' " default=u"A comment on '${title}' "
"has been posted here: ${link}") "has been posted here: ${link}")
logger = logging.getLogger("plone.app.discussion")
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable, class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
RoleManager, Owned, Implicit, Persistent): RoleManager, Owned, Implicit, Persistent):
@ -223,17 +230,29 @@ def notify_user(obj, event):
# Send email # Send email
if PLONE_4: if PLONE_4:
try:
mail_host.send(message, mail_host.send(message,
comment.author_email, comment.author_email,
sender, sender,
subject, subject,
charset='utf-8') charset='utf-8')
else: except SMTPException:
logger.error('SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
comment.author_email)
else: # pragma: no cover
try:
mail_host.secureSend(message, mail_host.secureSend(message,
comment.author_email, comment.author_email,
sender, sender,
subject=subject, subject=subject,
charset='utf-8') # pragma: no cover charset='utf-8')
except SMTPException:
logger.error('SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
comment.author_email)
def notify_moderator(obj, event): def notify_moderator(obj, event):
"""Tell the moderator when a comment needs attention. """Tell the moderator when a comment needs attention.
@ -284,10 +303,22 @@ def notify_moderator(obj, event):
# Send email # Send email
if PLONE_4: if PLONE_4:
try:
mail_host.send(message, mto, sender, subject, charset='utf-8') mail_host.send(message, mto, sender, subject, charset='utf-8')
else: except SMTPException:
logger.error('SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
comment.author_email)
else: # pragma: no cover
try:
mail_host.secureSend(message, mail_host.secureSend(message,
mto, mto,
sender, sender,
subject=subject, subject=subject,
charset='utf-8') # pragma: no cover charset='utf-8')
except SMTPException:
logger.error('SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
comment.author_email)