Catch SMTP exceptions when sending email notifications.
svn path=/plone.app.discussion/trunk/; revision=45199
This commit is contained in:
		
							parent
							
								
									13e9d54793
								
							
						
					
					
						commit
						cbd2edf932
					
				@ -1,6 +1,13 @@
 | 
			
		||||
Changelog
 | 
			
		||||
=========
 | 
			
		||||
 | 
			
		||||
1.0RC1 (unreleased)
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
- Catch SMTP exceptions when sending email notifications.
 | 
			
		||||
  [timo]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
1.0b12 (2010-11-04)
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,13 @@
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
"""The default comment class and factory.
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
 | 
			
		||||
from smtplib import SMTPException
 | 
			
		||||
 | 
			
		||||
from zope.annotation.interfaces import IAnnotatable
 | 
			
		||||
 | 
			
		||||
from zope.component.factory import Factory
 | 
			
		||||
@ -52,6 +57,8 @@ MAIL_NOTIFICATION_MESSAGE = _(u"mail_notification_message",
 | 
			
		||||
    default=u"A comment on '${title}' "
 | 
			
		||||
             "has been posted here: ${link}")
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger("plone.app.discussion")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Comment(CatalogAware, WorkflowAware, DynamicType, Traversable,
 | 
			
		||||
              RoleManager, Owned, Implicit, Persistent):
 | 
			
		||||
@ -223,17 +230,29 @@ def notify_user(obj, event):
 | 
			
		||||
        
 | 
			
		||||
            # Send email
 | 
			
		||||
            if PLONE_4:
 | 
			
		||||
                mail_host.send(message, 
 | 
			
		||||
                               comment.author_email, 
 | 
			
		||||
                               sender, 
 | 
			
		||||
                               subject, 
 | 
			
		||||
                               charset='utf-8')
 | 
			
		||||
            else:
 | 
			
		||||
                mail_host.secureSend(message, 
 | 
			
		||||
                                     comment.author_email, 
 | 
			
		||||
                                     sender, 
 | 
			
		||||
                                     subject=subject, 
 | 
			
		||||
                                     charset='utf-8') # pragma: no cover
 | 
			
		||||
                try:
 | 
			
		||||
                    mail_host.send(message, 
 | 
			
		||||
                                   comment.author_email, 
 | 
			
		||||
                                   sender, 
 | 
			
		||||
                                   subject, 
 | 
			
		||||
                                   charset='utf-8')
 | 
			
		||||
                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, 
 | 
			
		||||
                                         comment.author_email,
 | 
			
		||||
                                         sender,
 | 
			
		||||
                                         subject=subject,
 | 
			
		||||
                                         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):
 | 
			
		||||
    """Tell the moderator when a comment needs attention.
 | 
			
		||||
@ -284,10 +303,22 @@ def notify_moderator(obj, event):
 | 
			
		||||
 | 
			
		||||
    # Send email
 | 
			
		||||
    if PLONE_4:
 | 
			
		||||
        mail_host.send(message, mto, sender, subject, charset='utf-8')
 | 
			
		||||
    else:
 | 
			
		||||
        mail_host.secureSend(message, 
 | 
			
		||||
                             mto, 
 | 
			
		||||
                             sender, 
 | 
			
		||||
                             subject=subject, 
 | 
			
		||||
                             charset='utf-8') # pragma: no cover
 | 
			
		||||
        try:
 | 
			
		||||
            mail_host.send(message, mto, sender, subject, charset='utf-8')
 | 
			
		||||
        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, 
 | 
			
		||||
                                 mto, 
 | 
			
		||||
                                 sender, 
 | 
			
		||||
                                 subject=subject, 
 | 
			
		||||
                                 charset='utf-8')
 | 
			
		||||
        except SMTPException:
 | 
			
		||||
            logger.error('SMTP exception while trying to send an ' +
 | 
			
		||||
                         'email from %s to %s',
 | 
			
		||||
                         sender,
 | 
			
		||||
                         comment.author_email)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user