Example #1
0
    def test_create_message_with_extra_headers(self):
        request = testing.DummyRequest()

        message = create_message(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {
                'name': 'John',
                'email': '*****@*****.**'
            },
            'Testing message',
            ['*****@*****.**'],
            extra_headers={'foo': 'bar'},
        )
        self.assertEqual(message.subject, 'Testing message')
        self.assertEqual(
            message.html,
            '<p>Hello John,</p>\n\n<p>this is your email address: [email protected]</p>'
        )
        self.assertEqual(
            message.body,
            'Hello John,\n\nthis is your email address: [email protected]\n')
        self.assertEqual(message.recipients, ['*****@*****.**'])
        self.assertEqual(message.attachments, [])
        self.assertEqual(message.extra_headers, {'foo': 'bar'})
Example #2
0
    def test_create_message_with_attachments(self):
        request = testing.DummyRequest()

        attachment = Attachment('foo.txt', 'text/plain', 'test')

        message = create_message(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {
                'name': 'John',
                'email': '*****@*****.**'
            },
            'Testing message',
            ['*****@*****.**'],
            attachments=[attachment],
        )
        self.assertEqual(message.subject, 'Testing message')
        self.assertEqual(
            message.html,
            '<p>Hello John,</p>\n\n<p>this is your email address: [email protected]</p>'
        )
        self.assertEqual(
            message.body,
            'Hello John,\n\nthis is your email address: [email protected]\n')
        self.assertEqual(message.recipients, ['*****@*****.**'])
        self.assertEqual(message.extra_headers, {})
        self.assertEqual(len(message.attachments), 1)
        a = message.attachments[0]
        self.assertEqual(a.filename, 'foo.txt')
        self.assertEqual(a.content_type, 'text/plain')
        self.assertEqual(a.data, 'test')
def send_email(request, email_template, user, preferences_link):
    safe_print('Sending email to %s' % get_user_display_name(user))
    context = {'user': user, 'preferences_link': preferences_link}
    return create_message(
        request,
        'yithlibraryserver.scripts:templates/%s' % email_template,
        context,
        "Yith Library announcement",
        [user['email']],
    )
Example #4
0
def send_email(request, email_template, user, preferences_link):
    safe_print('Sending email to %s' % get_user_display_name(user))
    context = {'user': user, 'preferences_link': preferences_link}
    return create_message(
        request,
        'yithlibraryserver.scripts:templates/%s' % email_template,
        context,
        "Yith Library announcement",
        [user.email],
    )
 def test_create_message(self):
     request = testing.DummyRequest()
     message = create_message(
         request,
         'yithlibraryserver.tests:templates/email_test',
         {'name': 'John', 'email': '*****@*****.**'},
         'Testing message', ['*****@*****.**'],
     )
     self.assertEqual(message.subject, 'Testing message')
     self.assertEqual(message.html, '<p>Hello John,</p>\n\n<p>this is your email address: [email protected]</p>')
     self.assertEqual(message.body, 'Hello John,\n\nthis is your email address: [email protected]\n')
     self.assertEqual(message.recipients, ['*****@*****.**'])
     self.assertEqual(message.attachments, [])
     self.assertEqual(message.extra_headers, {})
    def test_create_message_with_attachments(self):
        request = testing.DummyRequest()

        attachment = Attachment('foo.txt', 'text/plain', 'test')

        message = create_message(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {'name': 'John', 'email': '*****@*****.**'},
            'Testing message', ['*****@*****.**'],
            attachments=[attachment],
        )
        self.assertEqual(message.subject, 'Testing message')
        self.assertEqual(message.html, '<p>Hello John,</p>\n\n<p>this is your email address: [email protected]</p>')
        self.assertEqual(message.body, 'Hello John,\n\nthis is your email address: [email protected]\n')
        self.assertEqual(message.recipients, ['*****@*****.**'])
        self.assertEqual(message.extra_headers, {})
        self.assertEqual(len(message.attachments), 1)
        a = message.attachments[0]
        self.assertEqual(a.filename, 'foo.txt')
        self.assertEqual(a.content_type, 'text/plain')
        self.assertEqual(a.data, 'test')