def get_templated_mail(template_name,
                       context,
                       from_email=None,
                       to=None,
                       cc=None,
                       bcc=None,
                       headers=None,
                       template_prefix=None,
                       template_suffix=None,
                       template_dir=None,
                       attach=[],
                       file_extension=None):
    """Returns a templated EmailMessage instance without a connection using
    the django templating backend."""
    template_prefix = template_prefix or template_dir
    template_suffix = template_suffix or file_extension
    templater = TemplateBackend(template_prefix=template_prefix,
                                template_suffix=template_suffix)
    return templater.get_email_message(template_name,
                                       context,
                                       from_email=from_email,
                                       to=to,
                                       cc=cc,
                                       bcc=bcc,
                                       headers=headers,
                                       template_prefix=template_prefix,
                                       template_suffix=template_suffix,
                                       attachments=attach)
 def setUp(self):
     self.backend = TemplateBackend()
     self.inline_image = InlineImage('foo.png', base64.b64decode(imageb64))
     self.message = self.backend.get_email_message(
         'inline_image.email', {'image_file': self.inline_image},
         from_email='*****@*****.**',
         cc=['*****@*****.**'],
         bcc=['*****@*****.**'],
         to=['*****@*****.**'])
def get_templated_mail(template_name, context, from_email=None, to=None,
                       cc=None, bcc=None, headers=None,
                       template_prefix=None, template_suffix=None,
                       template_dir=None, file_extension=None):
    """Returns a templated EmailMessage instance without a connection using
    the django templating backend."""
    template_prefix = template_prefix or template_dir
    template_suffix = template_suffix or file_extension
    templater = TemplateBackend(template_prefix=template_prefix,
                                template_suffix=template_suffix)
    return templater.get_email_message(template_name, context,
                                       from_email=from_email, to=to,
                                       cc=cc, bcc=bcc, headers=headers,
                                       template_prefix=template_prefix,
                                       template_suffix=template_suffix)
 def setUp(self):
     self.backend = TemplateBackend()
     self.inline_image = InlineImage('foo.png', base64.b64decode(imageb64))
     self.message = self.backend.get_email_message(
         'inline_image.email', {'image_file': self.inline_image},
         from_email='*****@*****.**', cc=['*****@*****.**'],
         bcc=['*****@*****.**'], to=['*****@*****.**'])
class GetMessageWithInlineMessageTestCase(MockedNetworkTestCaseMixin, TestCase):
    def setUp(self):
        self.backend = TemplateBackend()
        self.inline_image = InlineImage('foo.png', base64.b64decode(imageb64))
        self.message = self.backend.get_email_message(
            'inline_image.email', {'image_file': self.inline_image},
            from_email='*****@*****.**', cc=['*****@*****.**'],
            bcc=['*****@*****.**'], to=['*****@*****.**'])

    def test_cid_in_message(self):
        alternative_message = self.message.alternatives[0][0]
        self.assertIn('cid:%s' % unquote(self.inline_image._content_id),
                      alternative_message)

    def test_image_in_attachments(self):
        mimage = self.message.attachments[0]
        attachment_content = base64.b64encode(mimage.get_payload(decode=True))
        self.assertEquals(attachment_content.decode(), imageb64)
class GetMessageWithInlineMessageTestCase(MockedNetworkTestCaseMixin,
                                          TestCase):
    def setUp(self):
        self.backend = TemplateBackend()
        self.inline_image = InlineImage('foo.png', base64.b64decode(imageb64))
        self.message = self.backend.get_email_message(
            'inline_image.email', {'image_file': self.inline_image},
            from_email='*****@*****.**',
            cc=['*****@*****.**'],
            bcc=['*****@*****.**'],
            to=['*****@*****.**'])

    def test_cid_in_message(self):
        alternative_message = self.message.alternatives[0][0]
        self.assertIn('cid:%s' % unquote(self.inline_image._content_id),
                      alternative_message)

    def test_image_in_attachments(self):
        mimage = self.message.attachments[0]
        attachment_content = base64.b64encode(mimage.get_payload(decode=True))
        self.assertEquals(attachment_content.decode(), imageb64)