Ejemplo n.º 1
0
    def sendNotification(self, addresses, message):
        """Send ``message`` to all ``addresses``."""
        mailhosts = self.superValues(MAIL_HOST_META_TYPES)
        if not mailhosts:
            raise MailHostNotFound

        from Products.MaildropHost import MaildropHost
        bfound = False
        for mh in mailhosts:
            if isinstance(mh, MaildropHost):
                mailhost = mh
                bfound = True
            if bfound == True:
                break

        if bfound == False:
            mailhost = mailhosts[0]

        ptool = getToolByName(self, 'portal_properties').site_properties
        encoding = ptool.getProperty('default_charset', 'utf-8')
        message = encodeMailHeaders(message, encoding)

        if self.getProperty('debug_mode'):
            LOG.info('About to send this message to %s: \n%s', addresses,
                     message)

        n_messages_sent = 0
        for address in addresses:
            this_message = ('To: %s\n' % address) + message
            this_message = this_message.encode(encoding)
            try:
                mailhost.send(this_message)
                n_messages_sent += 1
            except ConflictError:
                raise
            except:
                LOG.error('Error while sending '\
                          'notification: \n%s' % this_message,
                          exc_info=True)
        return n_messages_sent
    def sendNotification(self, addresses, message):
        """Send ``message`` to all ``addresses``."""	
        mailhosts = self.superValues(MAIL_HOST_META_TYPES)
        if not mailhosts:
            raise MailHostNotFound
	
	from Products.MaildropHost import MaildropHost
	bfound = False
	for mh in mailhosts:
	    if isinstance(mh,MaildropHost):
	        mailhost = mh
		bfound = True
	    if bfound == True:
	        break
	
	if bfound == False:
	    mailhost = mailhosts[0]

        ptool = getToolByName(self, 'portal_properties').site_properties
        encoding = ptool.getProperty('default_charset', 'utf-8')
        message = encodeMailHeaders(message, encoding)

        if self.getProperty('debug_mode'):
            LOG.info('About to send this message to %s: \n%s',
                     addresses, message)

        n_messages_sent = 0
        for address in addresses:
            this_message = ('To: %s\n' % address) + message
            this_message = this_message.encode(encoding)
            try:
                mailhost.send(this_message)
                n_messages_sent += 1
            except ConflictError:
                raise
            except:
                LOG.error('Error while sending '\
                          'notification: \n%s' % this_message,
                          exc_info=True)
        return n_messages_sent
Ejemplo n.º 3
0
    def sendNotification(self, obj, address, message):
        """Send ``message`` to ``address``."""
        portal = obj.restrictedTraverse('@@plone_portal_state').portal()
        mailhosts = portal.superValues(NotificationTool.MAIL_HOST_META_TYPES)
        if not mailhosts:
            raise MailHostNotFound
        mailhost = mailhosts[0]

        ptool = getToolByName(obj, 'portal_properties').site_properties
        encoding = ptool.getProperty('default_charset', 'utf-8')
        message = encodeMailHeaders(message, encoding)

        this_message = ('To: %s\n' % address) + message
        this_message = this_message.encode(encoding)
        try:
            mailhost.send(this_message)
        except ConflictError:
            raise
        except:
            LOG.error('Error while sending '\
                      'notification: \n%s' % this_message,
                      exc_info=True)
            return 0
        return 1
Ejemplo n.º 4
0
    def sendNotification(self, obj, address, message):
        """Send ``message`` to ``address``."""
        portal = obj.restrictedTraverse('@@plone_portal_state').portal()
        mailhosts = portal.superValues(MAIL_HOST_META_TYPES)
        if not mailhosts:
            raise MailHostNotFound
        mailhost = mailhosts[0]

        ptool = getToolByName(obj, 'portal_properties').site_properties
        encoding = ptool.getProperty('default_charset', 'utf-8')
        message = encodeMailHeaders(message, encoding)

        this_message = ('To: %s\n' % address) + message
        this_message = this_message.encode(encoding)
        try:
            mailhost.send(this_message)
        except ConflictError:
            raise
        except:
            LOG.error('Error while sending '\
                      'notification: \n%s' % this_message,
                      exc_info=True)
            return 0
        return 1
Ejemplo n.º 5
0
 def testEncoding(self):
     for raw, expected in MESSAGES:
         encoded = encodeMailHeaders(raw, 'utf-8')
         self.failUnlessEqual(encoded, expected)
Ejemplo n.º 6
0
 def testEncoding(self):
     for raw, expected in MESSAGES:
         encoded = encodeMailHeaders(raw, 'utf-8')
         self.failUnlessEqual(encoded, expected)