예제 #1
0
    def send_messages(self, email_messages, **kwargs):
        for msg in email_messages:
            params = {'utm_source': msg.subject,
                      'utm_medium': 'email',
                      'utm_campaign': 'webapp',
                      }

            if replace_text and msg.content_subtype == 'text':
                msg.body = replace_urls_text(msg.body, params)
            elif msg.content_subtype == 'html':
                msg.body = replace_urls_html(msg.body, params)

            if getattr(msg, 'alternatives', False):
                alts = []
                for content, mimetype in msg.alternatives:
                    if content is not None and mimetype == 'text/html':
                        content = replace_urls_html(content, params)
                alts.append((content, mimetype))
                msg.alternatives = alts

        conn = get_connection(backend=chained_backend, **self.init_kwargs)
        return conn.send_messages(email_messages)
예제 #2
0
    def send_messages(self, email_messages, **kwargs):
        for msg in email_messages:
            params = {
                'utm_source': msg.subject,
                'utm_medium': 'email',
                'utm_campaign': 'webapp',
            }

            if replace_text and msg.content_subtype == 'text':
                msg.body = replace_urls_text(msg.body, params)
            elif msg.content_subtype == 'html':
                msg.body = replace_urls_html(msg.body, params)

            if getattr(msg, 'alternatives', False):
                alts = []
                for content, mimetype in msg.alternatives:
                    if content is not None and mimetype == 'text/html':
                        content = replace_urls_html(content, params)
                alts.append((content, mimetype))
                msg.alternatives = alts

        conn = get_connection(backend=chained_backend, **self.init_kwargs)
        return conn.send_messages(email_messages)
예제 #3
0
    def test_html_replacements(self):

        params = {'test': 'test'}

        html = """
               http://example.com <a href="http://example.com">http://example.com</a>.<br>
               <a href= "http://example.com">text</a>
               """
        r_html = """
               http://example.com <a href="http://example.com?test=test">http://example.com</a>.<br>
               <a href= "http://example.com?test=test">text</a>
               """

        self.assertEqual(replace_urls_html(html, params),
                         str(BeautifulSoup(r_html, "html.parser")))