Skip to content

Commit 7c54d96

Browse files
committed
Merge pull request #66 from SparkPost/ISSUE-62
Updates to documentation/examples
2 parents f4666f6 + 00a81ed commit 7c54d96

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

docs/resources/transmissions.rst

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Here at SparkPost, our messages are known as transmissions. Let's use the underl
99
1010
sp = SparkPost()
1111
12-
response = sp.transmission.send(
12+
response = sp.transmissions.send(
1313
recipients=['[email protected]'],
1414
html='<p>Hello world</p>',
1515
from_email='[email protected]',
@@ -43,7 +43,7 @@ Using inline templates and/or recipients
4343
4444
sp = SparkPost()
4545
46-
sp.transmission.send(
46+
sp.transmissions.send(
4747
recipients=['[email protected]'],
4848
text="Hello world",
4949
html='<p>Hello world</p>',
@@ -63,7 +63,7 @@ Sending an attachment
6363
6464
sp = SparkPost()
6565
66-
sp.transmission.send(
66+
sp.transmissions.send(
6767
recipients=['[email protected]'],
6868
text="Hello world",
6969
html='<p>Hello world</p>',
@@ -81,6 +81,33 @@ Sending an attachment
8181
)
8282
8383
84+
Using substitution data
85+
***********************
86+
87+
.. note::
88+
89+
Substitution data can be specified at the template, transmission and recipient levels. The order of precedence is as follows: recipient overrides transmission overrides template.
90+
91+
.. code-block:: python
92+
93+
from sparkpost import SparkPost
94+
95+
sp = SparkPost()
96+
97+
sp.transmissions.send(
98+
recipients=['[email protected]'],
99+
text="Hello {{name}}",
100+
html='<p>Hello {{name}}</p>',
101+
from_email='[email protected]',
102+
subject='Hello from python-sparkpost',
103+
track_opens=True,
104+
track_clicks=True,
105+
substitution_data={
106+
'name': 'Sparky'
107+
}
108+
)
109+
110+
84111
Using a stored template
85112
***********************
86113

@@ -90,7 +117,7 @@ Using a stored template
90117
91118
sp = SparkPost()
92119
93-
sp.transmission.send(
120+
sp.transmissions.send(
94121
recipients=['[email protected]'],
95122
template='my-template-id'
96123
)
@@ -105,7 +132,7 @@ Using a stored recipient list
105132
106133
sp = SparkPost()
107134
108-
sp.transmission.send(
135+
sp.transmissions.send(
109136
recipient_list='my-recipient-list',
110137
template='my-template-id'
111138
)
@@ -120,7 +147,7 @@ Retrieve a transmission
120147
121148
sp = SparkPost()
122149
123-
sp.transmission.get('my-transmission-id')
150+
sp.transmissions.get('my-transmission-id')
124151
125152
126153
List all transmissions
@@ -132,7 +159,7 @@ List all transmissions
132159
133160
sp = SparkPost()
134161
135-
sp.transmission.list()
162+
sp.transmissions.list()
136163
137164
138165
API reference

examples/transmissions/a-file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Woo hoo! This attachment was added via python-sparkpost.

examples/transmissions/send_transmission.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import os
2+
13
from sparkpost import SparkPost
24

5+
parent_dir = os.path.dirname(os.path.realpath(__file__))
6+
attachment_path = os.path.abspath(os.path.join(parent_dir, "a-file.txt"))
7+
38
sp = SparkPost()
49

510
response = sp.transmissions.send(
@@ -13,8 +18,8 @@
1318
}
1419
}
1520
],
16-
html='<p>Hello world {{name}}</p>',
17-
text='Hello world {{name}}',
21+
html='<p>Hello {{name}}</p>',
22+
text='Hello {{name}}',
1823
from_email='[email protected]',
1924
subject='Example Script',
2025
description='contrived example',
@@ -23,6 +28,13 @@
2328
},
2429
track_opens=True,
2530
track_clicks=True,
31+
attachments=[
32+
{
33+
"name": "test.txt",
34+
"type": "text/plain",
35+
"filename": attachment_path
36+
}
37+
],
2638
campaign='sdk example',
2739
metadata={
2840
'key': 'value',

0 commit comments

Comments
 (0)