Esempio n. 1
0
    async def send_immediately(self,
                               recipient=None,
                               subject=None,
                               message=None,
                               text=None,
                               html=None,
                               sender=None,
                               message_id=None,
                               endpoint='default',
                               fail_silently=False):
        if sender is None:
            sender = self.settings.get('default_sender')
        message = self.get_message(recipient,
                                   subject,
                                   sender,
                                   message,
                                   text,
                                   html,
                                   message_id=message_id)
        encoding.cleanup_message(message)
        if message['Date'] is None:
            message['Date'] = formatdate()

        try:
            return await self._send(sender, [recipient], message, endpoint)
        except smtplib.socket.error:
            if not fail_silently:
                raise
Esempio n. 2
0
 def send(self, fromaddr, toaddrs, message):
     if not isinstance(message, Message):
         raise ValueError('Message must be email.message.Message')
     encoding.cleanup_message(message)
     messageid = message['Message-Id']
     if messageid is None:
         messageid = message['Message-Id'] = make_msgid('repoze.sendmail')
     if message['Date'] is None:
         message['Date'] = formatdate()
     managedMessage = self.createDataManager(fromaddr, toaddrs, message)
     managedMessage.join_transaction()
     return messageid
Esempio n. 3
0
 def send(self, fromaddr, toaddrs, message):
     if not isinstance(message, Message):
         raise ValueError('Message must be email.message.Message')
     encoding.cleanup_message(message)
     messageid = message['Message-Id']
     if messageid is None:
         messageid = message['Message-Id'] = make_msgid('repoze.sendmail')
     if message['Date'] is None:
         message['Date'] = formatdate()
     managedMessage = self.createDataManager(fromaddr, toaddrs, message)
     managedMessage.join_transaction()
     return messageid
Esempio n. 4
0
 def send(self, fromaddr, toaddrs, message):
     assert isinstance(message, Message), \
            'Message must be instance of email.message.Message'
     encoding.cleanup_message(message)
     messageid = message['Message-Id']
     if messageid is None:
         messageid = message['Message-Id'] = make_msgid('repoze.sendmail')
     if message['Date'] is None:
         message['Date'] = formatdate()
     transaction.get().join(
         self.createDataManager(fromaddr, toaddrs, message))
     return messageid
Esempio n. 5
0
 def send(self, fromaddr, toaddrs, message):
     assert isinstance(message, Message), \
            'Message must be instance of email.message.Message'
     encoding.cleanup_message(message)
     messageid = message['Message-Id']
     if messageid is None:
         messageid = message['Message-Id'] = make_msgid('repoze.sendmail')
     if message['Date'] is None:
         message['Date'] = formatdate()
     transaction.get().join(
         self.createDataManager(fromaddr, toaddrs, message))
     return messageid
Esempio n. 6
0
 def send(self, mto, msg):
     assert isinstance(msg, Message), \
            'Message must be instance of email.message.Message'
     try:
         from repoze.sendmail import encoding
         encoding.cleanup_message(msg)
     except ImportError:
         pass
     messageid = msg['Message-Id']
     if messageid is None:
         settings = get_config_settings()
         msgid_domain = settings.get('msgid_domain', None)
         messageid = msg['Message-Id'] = make_msgid(domain=msgid_domain)
     if msg['Date'] is None:
         msg['Date'] = formatdate()
     transaction.get().join(self.createDataManager(self.mfrom, mto, msg))
     return messageid
Esempio n. 7
0
    def send(self, mto, message):
        """
        keep in mind...
        This is only called inside another thread, after
        transaction has completed
        """
        try:
            from repoze.sendmail import encoding
            encoding.cleanup_message(message)
        except ImportError:
            pass
        messageid = message['Message-Id']
        if messageid is None:
            msgid_domain = self.msgid_domain
            messageid = message['Message-Id'] = make_msgid(domain=msgid_domain)
        if message['Date'] is None:
            message['Date'] = formatdate()

        message['X-Actually-From'] = Header(self.mfrom, 'utf-8')
        message['X-Actually-To'] = Header(','.join(mto), 'utf-8')
        maildir = Maildir(self.queuePath, True)
        tx_message = maildir.add(message)
        tx_message.commit()
        return messageid
Esempio n. 8
0
    def test_repoze_sendmail_send_to_queue_functional(self):
        # functest that emulates the interaction between tgext.mailer and
        # repoze.maildir.add and queuedelivery.send.
        
        import tempfile
        from email.generator import Generator
        from email.parser import Parser
        from tgext.mailer.message import Message
        from tgext.mailer.message import Attachment
        from repoze.sendmail.encoding import cleanup_message
        from repoze.sendmail.delivery import copy_message

        def checkit(msg):
            self.assertEqual(
                msg['Content-Type'],
                'text/plain; charset="iso-8859-1"'
                )
            self.assertEqual(
                msg['Content-Transfer-Encoding'], transfer_encoding)

            payload = msg.get_payload()
            self.assertEqual(payload, expected)

        charset = 'iso-8859-1'
        text_encoded = b'LaPe\xf1a'
        text = text_encoded.decode(charset)
        expected = _qencode(text_encoded).decode('ascii')
        transfer_encoding = 'quoted-printable'
        body = Attachment(
            data=text,
            transfer_encoding=transfer_encoding
            )
        msg = Message(
            subject="testing",
            sender="*****@*****.**",
            recipients=["*****@*****.**"],
            body=body
            )

        # done in tgext.mailer via mailer/send_to_queue
        msg = msg.to_message()
        msg.as_string()

        checkit(msg)

        # done in repoze.sendmail via delivery/AbstractMailDelivery/send
        cleanup_message(msg)

        checkit(msg)

        # done in repoze.sendmail via
        # delivery/AbstractMailDelivery/createDataManager
        msg_copy = copy_message(msg)

        checkit(msg_copy)

        try:
            # emulate what repoze.sendmail maildir.py/add does
            fn = tempfile.mktemp()
            fd = os.open(fn,
                         os.O_CREAT|os.O_EXCL|os.O_WRONLY,
                         0o600
                         )
            with os.fdopen(fd, 'w') as f:
                writer = Generator(f)
                writer.flatten(msg_copy)

            # emulate what repoze.sendmail.queue _parseMessage does
            with open(fn) as foo:
                parser = Parser()
                reconstituted = parser.parse(foo)
                checkit(reconstituted)
                
        finally: # pragma: no cover
            try:
                os.remove(fn)
            except:
                pass
Esempio n. 9
0
    def test_repoze_sendmail_send_to_queue_functional(self):
        # functest that emulates the interaction between pyramid_mailer and
        # repoze.maildir.add and queuedelivery.send.
        
        import tempfile
        from email.generator import Generator
        from email.parser import Parser
        from pyramid_mailer.message import Message
        from pyramid_mailer.message import Attachment
        from repoze.sendmail.encoding import cleanup_message
        from repoze.sendmail.delivery import copy_message

        def checkit(msg):
            self.assertEqual(
                msg['Content-Type'],
                'text/plain; charset="iso-8859-1"'
                )
            self.assertEqual(
                msg['Content-Transfer-Encoding'], transfer_encoding)

            payload = msg.get_payload()
            self.assertEqual(payload, expected)

        charset = 'iso-8859-1'
        text_encoded = b'LaPe\xf1a'
        text = text_encoded.decode(charset)
        expected = _qencode(text_encoded).decode('ascii')
        transfer_encoding = 'quoted-printable'
        body = Attachment(
            data=text,
            transfer_encoding=transfer_encoding
            )
        msg = Message(
            subject="testing",
            sender="*****@*****.**",
            recipients=["*****@*****.**"],
            body=body
            )

        # done in pyramid_mailer via mailer/send_to_queue
        msg = msg.to_message()
        msg.as_string()

        checkit(msg)

        # done in repoze.sendmail via delivery/AbstractMailDelivery/send
        cleanup_message(msg)

        checkit(msg)

        # done in repoze.sendmail via
        # delivery/AbstractMailDelivery/createDataManager
        msg_copy = copy_message(msg)

        checkit(msg_copy)

        try:
            # emulate what repoze.sendmail maildir.py/add does
            fn = tempfile.mktemp()
            fd = os.open(fn,
                         os.O_CREAT|os.O_EXCL|os.O_WRONLY,
                         0o600
                         )
            with os.fdopen(fd, 'w') as f:
                writer = Generator(f)
                writer.flatten(msg_copy)

            # emulate what repoze.sendmail.queue _parseMessage does
            with open(fn) as foo:
                parser = Parser()
                reconstituted = parser.parse(foo)
                checkit(reconstituted)
                
        finally: # pragma: no cover
            try:
                os.remove(fn)
            except:
                pass