Ejemplo n.º 1
0
    def send(self, message, fromaddr, toaddrs, subject=None, encode=None):
        """ Send out a mail.
            'subject' and 'encode' are unused (and kept right now
            for backward compatibility.
        """

        delivery = DirectMailDelivery(self._getMailer())
        delivery.send(fromaddr, toaddrs, message)
        LOG.debug('Sending mail from %s to %s succeeded' % (fromaddr, toaddrs))
Ejemplo n.º 2
0
    def send(self, message, fromaddr, toaddrs, subject=None, encode=None):
        """ Send out an email.
            'subject' and 'encode' are unused (and kept right now
            for backward compatibility.
            'message' should be a properly formatted RFC-822 compliant
            email message (e.g. as produced by Python's email module.
            
        """

        delivery = DirectMailDelivery(self._getMailer())
        delivery.send(fromaddr, toaddrs, message)
        LOG.debug('Sending mail from %s to %s succeeded' % (fromaddr, toaddrs))
Ejemplo n.º 3
0
    def testRefusingMailerDiesInVote(self):
        from zope.sendmail.delivery import DirectMailDelivery
        mailer = RefusingMailerStub()
        delivery = DirectMailDelivery(mailer)
        fromaddr = 'Jim <*****@*****.**'
        toaddrs = ('Guido <*****@*****.**>',
                   'Steve <steve@examplecom>')
        opt_headers = ('From: Jim <*****@*****.**>\n'
                       'To: some-zope-coders:;\n'
                       'Date: Mon, 19 May 2003 10:17:36 -0400\n'
                       'Message-Id: <*****@*****.**>\n')
        message =     ('Subject: example\n'
                       '\n'
                       'This is just an example\n')

        msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
        try:
            try:
                transaction.commit()
            except:
                if transaction.get()._voted:
                    # We voted for commit then failed, reraise
                    raise
                else:
                    # We vetoed a commit, that's good.
                    pass
            else:
                self.fail("Did not raise an exception in vote")
        finally:
            # Clean up after ourselves
            transaction.abort()
Ejemplo n.º 4
0
    def testBrokenMailerErrorsAreEaten(self):
        from zope.testing.loggingsupport import InstalledHandler
        mailer = BrokenMailerStub()
        delivery = DirectMailDelivery(mailer)
        fromaddr = 'Jim <*****@*****.**'
        toaddrs = ('Guido <*****@*****.**>',
                   'Steve <steve@examplecom>')
        opt_headers = ('From: Jim <*****@*****.**>\n'
                       'To: some-zope-coders:;\n'
                       'Date: Mon, 19 May 2003 10:17:36 -0400\n'
                       'Message-Id: <*****@*****.**>\n')
        message = ('Subject: example\n'
                   '\n'
                   'This is just an example\n')

        delivery.send(fromaddr, toaddrs, opt_headers + message)
        log_handler = InstalledHandler('MailDataManager')
        self.addCleanup(log_handler.uninstall)
        self.addCleanup(transaction.abort)
        transaction.commit()
Ejemplo n.º 5
0
    def testRefusingMailerDiesInVote(self):
        mailer = RefusingMailerStub()
        delivery = DirectMailDelivery(mailer)
        fromaddr = 'Jim <*****@*****.**'
        toaddrs = ('Guido <*****@*****.**>',
                   'Steve <steve@examplecom>')
        opt_headers = ('From: Jim <*****@*****.**>\n'
                       'To: some-zope-coders:;\n'
                       'Date: Mon, 19 May 2003 10:17:36 -0400\n'
                       'Message-Id: <*****@*****.**>\n')
        message = ('Subject: example\n'
                   '\n'
                   'This is just an example\n')

        delivery.send(fromaddr, toaddrs, opt_headers + message)
        self.addCleanup(transaction.abort)

        with self.assertRaises(Exception):
            transaction.commit()
        self.assertFalse(transaction.get()._voted,
                         "We voted for commit then failed, reraise")
Ejemplo n.º 6
0
    def testSend(self):
        from zope.sendmail.delivery import DirectMailDelivery
        mailer = MailerStub()
        delivery = DirectMailDelivery(mailer)
        fromaddr = 'Jim <*****@*****.**'
        toaddrs = ('Guido <*****@*****.**>',
                   'Steve <steve@examplecom>')
        opt_headers = ('From: Jim <*****@*****.**>\n'
                       'To: some-zope-coders:;\n'
                       'Date: Mon, 19 May 2003 10:17:36 -0400\n'
                       'Message-Id: <*****@*****.**>\n')
        message =     ('Subject: example\n'
                       '\n'
                       'This is just an example\n')

        msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
        self.assertEquals(msgid, '*****@*****.**')
        self.assertEquals(mailer.sent_messages, [])
        transaction.commit()
        self.assertEquals(mailer.sent_messages,
                          [(fromaddr, toaddrs, opt_headers + message)])

        mailer.sent_messages = []
        msgid = delivery.send(fromaddr, toaddrs, message)
        self.assert_('@' in msgid)
        self.assertEquals(mailer.sent_messages, [])
        transaction.commit()
        self.assertEquals(len(mailer.sent_messages), 1)
        self.assertEquals(mailer.sent_messages[0][0], fromaddr)
        self.assertEquals(mailer.sent_messages[0][1], toaddrs)
        self.assert_(mailer.sent_messages[0][2].endswith(message))
        new_headers = mailer.sent_messages[0][2][:-len(message)]
        self.assert_(new_headers.find('Message-Id: <%s>' % msgid) != -1)

        mailer.sent_messages = []
        msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
        self.assertEquals(mailer.sent_messages, [])
        transaction.abort()
        self.assertEquals(mailer.sent_messages, [])
Ejemplo n.º 7
0
    def testBrokenMailerErrorsAreEaten(self):
        from zope.sendmail.delivery import DirectMailDelivery
        mailer = BrokenMailerStub()
        delivery = DirectMailDelivery(mailer)
        fromaddr = 'Jim <*****@*****.**'
        toaddrs = ('Guido <*****@*****.**>',
                   'Steve <steve@examplecom>')
        opt_headers = ('From: Jim <*****@*****.**>\n'
                       'To: some-zope-coders:;\n'
                       'Date: Mon, 19 May 2003 10:17:36 -0400\n'
                       'Message-Id: <*****@*****.**>\n')
        message =     ('Subject: example\n'
                       '\n'
                       'This is just an example\n')

        msgid = delivery.send(fromaddr, toaddrs, opt_headers + message)
        try:
            transaction.commit()
        finally:
            # Clean up after ourselves
            transaction.abort()