Exemplo n.º 1
0
    def __sendMail(self, from_addr, to_addrs, messageText, deferred, testing=False):
        if __debug__:
            self.parent.printCurrentView("transport.__sendMail")

        account = self.parent.account

        username         = None
        password         = None
        authRequired     = False
        securityRequired = False
        heloFallback     = True

        if account.useAuth:
            username     = account.username
            password     = account.password
            authRequired = True
            heloFallback = False

        if testing:
            retries = 0
            timeout = constants.TESTING_TIMEOUT
        else:
            retries = account.numRetries
            timeout = account.timeout

        if account.connectionSecurity == 'TLS':
            securityRequired = True

        msg = StringIO.StringIO(messageText)

        # Note that we cheat with the context factory here (value=1),
        # because ssl.connectSSL does it automatically, and in the
        # case of STARTTLS we override esmtpState_starttls above
        # to supply the correct SSL context.
        factory = smtp.ESMTPSenderFactory(username, password, from_addr, 
                                          to_addrs, msg,
                                          deferred, retries, timeout,
                                          1, heloFallback, authRequired, 
                                          securityRequired)

        factory.protocol   = _TwistedESMTPSender
        factory.testing    = testing

        if account.connectionSecurity == 'SSL':
            ssl.connectSSL(account.host, account.port, factory, 
                           self.parent.view)
        else:
            ssl.connectTCP(account.host, account.port, factory, 
                           self.parent.view)
Exemplo n.º 2
0
        self.factory = self.factoryType(self)
        """Cache the maximum number of messages to download before forcing a commit"""
        self.downloadMax = self.account.downloadMax

        if self.testing:
            """If in testing mode then do not want to retry connection or
               wait a long period for a timeout"""
            self.factory.retries = 0
            self.factory.timeout = constants.TESTING_TIMEOUT

        if self.account.connectionSecurity == 'SSL':
            ssl.connectSSL(self.account.host, self.account.port,
                           self.factory, self.view)
        else:
            ssl.connectTCP(self.account.host, self.account.port,
                           self.factory, self.view)
            
    def catchErrors(self, err):
        """
        This method captures all errors thrown while in the Twisted Reactor Thread.
        @param err: The error thrown
        @type err: C{failure.Failure} or c{Exception}

        @return: C{None}
        """
        if __debug__:
            self.printCurrentView("catchErrors")

        if isinstance(err, failure.Failure):
            err = err.value