Пример #1
0
    def transportMail(self, mailMessage):
        """
           Sends a mail message via SMTP using the C{SMTPAccount}
           passed to this classes parent

           @param mailMessage: A MailMessage content model object
           @type mailMessage: C{Mail.MailMessageMixin}

           @return: C{None}
        """

        if __debug__:
            self.parent.printCurrentView("transport.transportMail")

        self.mailMessage = mailMessage

        self.mailMessage.outgoingMessage(self.parent.account)

        """Clear out any previous DeliveryErrors from a previous attempt"""
        for item in self.mailMessage.deliveryExtension.deliveryErrors:
            item.delete()

        """Get the sender's Email Address will either be the Reply-To or From field"""
        sender = self.__getSender()

        if self.__mailMessageHasErrors(sender):
            return


        messageText = message.kindToMessageText(self.mailMessage)

        d = defer.Deferred()
        d.addCallback(self.parent.execInViewThenCommitInThreadDeferred, self.__mailSuccessCheck)
        d.addErrback(self.parent.execInViewThenCommitInThreadDeferred,  self.handleSSLError)
        d.addErrback(self.parent.execInViewThenCommitInThreadDeferred,  self.__mailFailure)

        self.__sendMail(sender.emailAddress, self.__getRcptTo(), messageText, d)
Пример #2
0
    def _prepareForSend(self, mailMessageUUID):
        """Sends a mail message via SMTP using the account and mailMessage
           passed to this classes __init__ method using the Twisted Asych Reactor"""

        if __debug__:
            trace("_prepareForSend")

        if self.cancel:
            return self._resetClient()

        # Refresh our view before retrieving Account info
        self.view.refresh()

        self._getAccount()

        # If currently sending a message put the next request in the Queue.
        try:
            # Just in case a cancel was requested after the above cancel check
            # return here instead of seeing if the message should go in the queue
            if self.cancel:
                return self._resetClient()

            msg = self._getMailMessage(mailMessageUUID)
            mailStampOccurrence, masterMailStamp = getRecurrenceMailStamps(msg)

            # The isOnline check is performed in the Twisted thread
            # so pass in a view.
            if self.mailMessage is not None or not Globals.mailService.isOnline(
                    self.view):
                newMessage = masterMailStamp

                try:
                    sending = (self.mailMessage.itsItem is newMessage.itsItem)
                except:
                    sending = False

                inQueue = False

                # Check that the mailMessage in not already Queued
                for item in self.account.messageQueue:
                    if item is newMessage.itsItem:
                        if __debug__:
                            trace(
                                "SMTPClient Queue already contains message: %s"
                                % mailMessageUUID)
                        inQueue = True

                #Sending should always be False in offline mode
                if not inQueue and sending:
                    # Check that the mailMessage in not currently being sent
                    if __debug__:
                        trace("SMTPClient currently sending message: %s" %
                              mailMessageUUID)

                elif not inQueue:
                    self.account.messageQueue.insert(0, newMessage.itsItem)

                    # Update the item state
                    newMessage.itsItem.changeEditState(
                        Modification.queued, who=newMessage.getSender())
                    self.view.commit()

                    if __debug__:
                        trace("SMTPClient adding to the Queue message: %s" %
                              mailMessageUUID)

                # The isOnline check is performed in the Twisted thread
                # so pass in a view.
                if not Globals.mailService.isOnline(self.view):
                    setStatusMessage(constants.UPLOAD_OFFLINE % \
                                    {'accountName': self.account.displayName,
                                     'subject': mailStampOccurrence.subject})

                return

            self.mailMessage = masterMailStamp

            setStatusMessage(constants.UPLOAD_START % \
                             {'accountName': self.account.displayName,
                              'subject': mailStampOccurrence.subject})

            # handles all MailStamp level logic  to support general sending
            # of mail as well as edit / update workflows
            masterMailStamp.outgoingMessage()

            sender = masterMailStamp.getSender()

            # use the individual occurrence, not the master, bug 9499
            messageText = kindToMessageText(mailStampOccurrence)

        except Exception, e:
            if __debug__:
                trace(e)

            return self._mailFailure(e)
Пример #3
0
    def _prepareForSend(self, mailMessageUUID):
        """Sends a mail message via SMTP using the account and mailMessage
           passed to this classes __init__ method using the Twisted Asych Reactor"""

        if __debug__:
            trace("_prepareForSend")

        if self.cancel:
            return self._resetClient()

        # Refresh our view before retrieving Account info
        self.view.refresh()

        self._getAccount()

        # If currently sending a message put the next request in the Queue.
        try:
            # Just in case a cancel was requested after the above cancel check
            # return here instead of seeing if the message should go in the queue
            if self.cancel:
                return self._resetClient()

            msg = self._getMailMessage(mailMessageUUID)
            mailStampOccurrence, masterMailStamp = getRecurrenceMailStamps(msg)

            # The isOnline check is performed in the Twisted thread
            # so pass in a view.
            if self.mailMessage is not None or not Globals.mailService.isOnline(self.view):
                newMessage = masterMailStamp

                try:
                    sending = (self.mailMessage.itsItem is newMessage.itsItem)
                except:
                    sending = False

                inQueue = False

                # Check that the mailMessage in not already Queued
                for item in self.account.messageQueue:
                    if item is newMessage.itsItem:
                        if __debug__:
                            trace("SMTPClient Queue already contains message: %s" % mailMessageUUID)
                        inQueue = True

                #Sending should always be False in offline mode
                if not inQueue and sending:
                    # Check that the mailMessage in not currently being sent
                    if __debug__:
                        trace("SMTPClient currently sending message: %s" % mailMessageUUID)

                elif not inQueue:
                    self.account.messageQueue.insert(0, newMessage.itsItem)

                    # Update the item state
                    newMessage.itsItem.changeEditState(Modification.queued,
                                                       who=newMessage.getSender())
                    self.view.commit()

                    if __debug__:
                        trace("SMTPClient adding to the Queue message: %s" % mailMessageUUID)

                # The isOnline check is performed in the Twisted thread
                # so pass in a view.
                if not Globals.mailService.isOnline(self.view):
                    setStatusMessage(constants.UPLOAD_OFFLINE % \
                                    {'accountName': self.account.displayName,
                                     'subject': mailStampOccurrence.subject})

                return

            self.mailMessage = masterMailStamp

            setStatusMessage(constants.UPLOAD_START % \
                             {'accountName': self.account.displayName,
                              'subject': mailStampOccurrence.subject})

            # handles all MailStamp level logic  to support general sending
            # of mail as well as edit / update workflows
            masterMailStamp.outgoingMessage()

            sender = masterMailStamp.getSender()

            # use the individual occurrence, not the master, bug 9499
            messageText = kindToMessageText(mailStampOccurrence)

        except Exception, e:
            if __debug__:
                trace(e)

            return self._mailFailure(e)