Exemple #1
0
def send_mail(subject, like, to):
    email = EmailMultiAlternatives(subject, like, '*****@*****.**', to)
    pic = InlineImage('spirit.jpg',
                      open(u'C:\spirit.jpg', 'rb').read(),
                      subtype='jpeg')
    pic.attach_to_message(email)
    html = render_to_string('emails/liked.html', {'spirit': pic, 'cool': like})
    email.attach_alternative(html, 'text/html')
    email.send()
Exemple #2
0
def send_digest(subject, posts, to):
    email = EmailMultiAlternatives(subject, str(posts), '*****@*****.**', to)
    pic = InlineImage('spirit.jpg',
                      open(u'C:\spirit.jpg', 'rb').read(),
                      subtype='jpeg')
    pic.attach_to_message(email)
    html = render_to_string('emails/digest.html', {
        'spirit': pic,
        'posts': posts
    })
    email.attach_alternative(html, 'text/html')
    email.send()
Exemple #3
0
    def send_welcome_letter(self):
        if settings.DEBUG:
            to = [admin[0] for admin in settings.ADMINS]
            # base_send_mail(subject, text, '*****@*****.**', to)

            email = EmailMultiAlternatives('Welcome', 'hi', '*****@*****.**', to)

            pic = InlineImage('pic.jpg', open('/home/lida/web_project_2sem/technotrack-web2-spring-2017/core/static/core/download.png','rb').read())
            pic.attach_to_message(email)
            html = render_to_string('email/welcome_letter.html', {'username': self.username, 'SITE_URL': settings.SITE_URL, 'pic': pic})
            email.attach_alternative(html, 'text/html')
            # email.attach('myfile.txt', 'THIS IS MY FILE', 'text/plain')
            email.send()
Exemple #4
0
class InlineMessageTestCase(MockedNetworkTestCaseMixin, TestCase):
    def setUp(self):
        self.inline_image = InlineImage('foo.png', 'content', 'png')

    def test_needs_two_args(self):
        with self.assertRaises(TypeError):
            InlineImage()
        with self.assertRaises(TypeError):
            InlineImage('foo')

    def test_has_no_cid(self):
        self.assertIsNone(self.inline_image._content_id)

    def test_generate_cid(self):
        str(self.inline_image)
        self.assertIsNotNone(self.inline_image._content_id)

    @mock.patch('templated_email.utils.make_msgid', return_value='foo')
    def test_str(self, mocked):
        self.assertEqual(str(self.inline_image), 'cid:foo')

    @mock.patch('templated_email.utils.make_msgid', return_value='foo')
    def test_should_cache_cid(self, mocked):
        str(self.inline_image)
        str(self.inline_image)
        mocked.assert_called_once()

    def test_changing_content_should_generate_new_cid(self):
        src_value = str(self.inline_image)
        cid = self.inline_image._content_id
        self.inline_image.content = 'content2'
        cid2 = self.inline_image._content_id
        src_value2 = str(self.inline_image)
        self.assertNotEqual(src_value, src_value2)
        cid3 = self.inline_image._content_id
        self.assertNotEqual(cid, cid2)
        self.assertNotEqual(cid2, cid3)

    def test_attach_to_message(self):
        message = mock.Mock()
        self.inline_image.attach_to_message(message)
        mimeimage = message.attach.call_args[0][0]
        self.assertEquals(mimeimage.get('Content-ID'),
                          self.inline_image._content_id)
        self.assertEquals(mimeimage.get('Content-Disposition'),
                          'inline; filename="foo.png"')
Exemple #5
0
def send_mail(subject, text, template, context, to):

    if settings.DEBUG:
        to = [admin[0] for admin in settings.ADMINS]
    email = EmailMultiAlternatives(subject, text, '*****@*****.**', to)

    pic = InlineImage(
        'pepe.png',
        open(
            '/Users/Oskar/Desktop/Phystech/Technotrack/WEB2/Project/src/core/static/images/pepe_logo.png',
            'rb').read(), 'image/png')
    pic.attach_to_message(email)
    context['pepe_logo'] = pic
    html = render_to_string(template, context)
    email.attach_alternative(html, 'text/html')

    email.send()
Exemple #6
0
    def send_digest_letter(self):
        to = [admin[0] for admin in settings.ADMINS]
        # base_send_mail(subject, text, '*****@*****.**', to)

        email = EmailMultiAlternatives('Welcome', 'hi', '*****@*****.**', to)

        pic = InlineImage('pic.jpg',
                          open('/home/lida/web_project_2sem/technotrack-web2-spring-2017/core/static/core/download.png',
                               'rb').read())
        pic.attach_to_message(email)

        html = render_to_string('email/digest_letter.html',
                                {'username': self.username, 'SITE_URL': settings.SITE_URL, 'pic': pic})

        #for object in User.following.through.objects.filter(from_user=self.id):
          #  events = Event.objects.filter(author_id=object.to_user)


        email.attach_alternative(html, 'text/html')

        # email.attach('myfile.txt', 'THIS IS MY FILE', 'text/plain')
        email.send()