How to use the sparkpost.django.message.SparkPostMessage function in sparkpost

To help you get started, we’ve selected a few sparkpost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_substitution_data():
    email_message = EmailMessage(
        to=[
            {
                "address": "to@example.com",
                "substitution_data": {
                    "key": "value"
                }
            }
        ],
        from_email='test@from.com'
    )
    email_message.template = 'template-id'
    email_message.substitution_data = {"key2": "value2"}
    actual = SparkPostMessage(email_message)

    expected = dict(
        recipients=[
            {
                "address": "to@example.com",
                "substitution_data": {
                    "key": "value"
                }
            }
        ],
        from_email='test@from.com',
        template='template-id',
        substitution_data={"key2": "value2"}
    )

    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_content_subtype():
    email_message = EmailMessage(
        to=['to@example.com'],
        from_email='test@from.com',
        body='<p>Testing</p>'
    )
    email_message.content_subtype = 'html'
    actual = SparkPostMessage(email_message)
    expected = dict(
        recipients=['to@example.com'],
        from_email='test@from.com',
        html='<p>Testing</p>'
    )
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def message(**options):
    options.update(base_options)
    email_message = EmailMessage(**options)
    return SparkPostMessage(email_message)
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_campaign():
    email_message = EmailMessage(**base_options)
    email_message.campaign = 'campaign-id'
    actual = SparkPostMessage(email_message)
    expected = dict(
        campaign='campaign-id'
    )
    expected.update(base_expected)
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_transactional():
    email_message = EmailMessage(**base_options)
    import json
    msys_api = json.dumps({'options': {'transactional': True}})
    email_message.extra_headers['X-MSYS-API'] = msys_api

    actual = SparkPostMessage(email_message)
    expected = dict(
        custom_headers={'X-MSYS-API': msys_api},
        transactional=True,
    )
    expected.update(base_expected)
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_template():
    email_message = EmailMessage(
        to=['to@example.com'],
        from_email='test@from.com'
    )
    email_message.template = 'template-id'
    actual = SparkPostMessage(email_message)
    expected = dict(
        recipients=['to@example.com'],
        from_email='test@from.com',
        template='template-id'
    )
    assert actual == expected
github SparkPost / python-sparkpost / test / django / test_message.py View on Github external
def test_attachment():
    email_message = EmailMessage(**base_options)
    email_message.attach('file.txt', 'test content', 'text/plain')

    actual = SparkPostMessage(email_message)
    expected = dict(
        attachments=[
            {
                'name': 'file.txt',
                'data': 'dGVzdCBjb250ZW50',
                'type': 'text/plain'
            }
        ]
    )
    expected.update(base_expected)
    assert actual == expected
github SparkPost / python-sparkpost / sparkpost / django / email_backend.py View on Github external
def send_messages(self, email_messages):
        """
        Send emails, returns integer representing number of successful emails
        """
        success = 0
        for message in email_messages:
            try:
                response = self._send(SparkPostMessage(message))
                success += response['total_accepted_recipients']
            except Exception:
                if not self.fail_silently:
                    raise
        return success