예제 #1
0
 def test_html(self):
     email = create_email_message(['*****@*****.**'], '*****@*****.**',
                                  'Subject', 'Email Body.',
                                  '<html>A</html>')
     email.send()
     expected_alternatives = [('<html>A</html>', 'text/html')]
     self.assertEqual(mail.outbox[0].alternatives, expected_alternatives)
예제 #2
0
    def send_unsent_scheduled_emails():
        """
        Send out any scheduled emails that are unsent
        """

        current_time = datetime.utcnow()
        email_medium = get_medium()
        to_send = Email.objects.filter(
            scheduled__lte=current_time, sent__isnull=True).select_related(
                'event').prefetch_related('recipients')

        # Fetch the contexts of every event so that they may be rendered
        context_loader.load_contexts_and_renderers([e.event for e in to_send],
                                                   [email_medium])

        emails = []
        for email in to_send:
            to_email_addresses = get_subscribed_email_addresses(email)
            if to_email_addresses:
                text_message, html_message = email.render(email_medium)
                message = create_email_message(
                    to_emails=to_email_addresses,
                    from_email=email.from_address or get_from_email_address(),
                    subject=email.subject
                    or extract_email_subject_from_html_content(html_message),
                    text=text_message,
                    html=html_message,
                )
                emails.append(message)

        connection = mail.get_connection()
        connection.send_messages(emails)
        to_send.update(sent=current_time)
 def test_html(self):
     email = create_email_message(
         ['*****@*****.**'], '*****@*****.**', 'Subject', 'Email Body.', '<html>A</html>'
     )
     email.send()
     expected_alternatives = [('<html>A</html>', 'text/html')]
     self.assertEqual(mail.outbox[0].alternatives, expected_alternatives)
    def send_unsent_scheduled_emails():
        """
        Send out any scheduled emails that are unsent
        """

        current_time = datetime.utcnow()
        email_medium = get_medium()
        to_send = Email.objects.filter(
            scheduled__lte=current_time,
            sent__isnull=True
        ).select_related(
            'event'
        ).prefetch_related(
            'recipients'
        )

        # Fetch the contexts of every event so that they may be rendered
        context_loader.load_contexts_and_renderers([e.event for e in to_send], [email_medium])

        emails = []
        for email in to_send:
            to_email_addresses = get_subscribed_email_addresses(email)
            if to_email_addresses:
                text_message, html_message = email.render(email_medium)
                message = create_email_message(
                    to_emails=to_email_addresses,
                    from_email=email.from_address or get_from_email_address(),
                    subject=email.subject or extract_email_subject_from_html_content(html_message),
                    text=text_message,
                    html=html_message,
                )
                emails.append(message)

        connection = mail.get_connection()
        connection.send_messages(emails)
        to_send.update(sent=current_time)
예제 #5
0
 def test_no_html(self):
     email = create_email_message(['*****@*****.**'], '*****@*****.**',
                                  'Subject', 'Email Body.', '')
     email.send()
     self.assertEqual(mail.outbox[0].attachments, [])
 def test_no_html(self):
     email = create_email_message(
         ['*****@*****.**'], '*****@*****.**', 'Subject', 'Email Body.', ''
     )
     email.send()
     self.assertEqual(mail.outbox[0].attachments, [])