File: send_transmission.py

package info (click to toggle)
python-sparkpost 1.3.10-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 512 kB
  • sloc: python: 2,528; makefile: 31; sh: 10
file content (49 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os

from sparkpost import SparkPost

parent_dir = os.path.dirname(os.path.realpath(__file__))
attachment_path = os.path.abspath(os.path.join(parent_dir, "a-file.txt"))

sp = SparkPost()

response = sp.transmissions.send(
    recipients=[
        'postmaster@example.com',
        'you@me.com',
        {
            'address': {
                'email': 'john.doe@example.com',
                'name': 'John Doe'
            }
        }
    ],
    cc=['carboncopy@example.com'],
    bcc=['blindcarboncopy@example.com'],
    html='<p>Hello {{name}}</p>',
    text='Hello {{name}}',
    from_email='Test User <test@sparkpostbox.com>',
    subject='Example Script',
    description='contrived example',
    custom_headers={
        'X-CUSTOM-HEADER': 'foo bar'
    },
    track_opens=True,
    track_clicks=True,
    attachments=[
        {
            "name": "test.txt",
            "type": "text/plain",
            "filename": attachment_path
        }
    ],
    campaign='sdk example',
    metadata={
        'key': 'value',
        'arbitrary': 'values'
    },
    substitution_data={
        'name': 'Example User'
    },
    reply_to='no-reply@sparkpostmail.com'
)