Skip to content

Commit 7be6972

Browse files
committed
Merge pull request #98 from SparkPost/ISSUE-86
Add support for ip pools, inline images
2 parents 89d9f13 + d5bc6a7 commit 7be6972

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

sparkpost/transmissions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def _translate_keys(self, **kwargs):
4040
model['options']['transactional'] = kwargs.get('transactional')
4141
model['options']['sandbox'] = kwargs.get('use_sandbox')
4242
model['options']['skip_suppression'] = kwargs.get('skip_suppression')
43+
model['options']['ip_pool'] = kwargs.get('ip_pool')
4344
model['options']['inline_css'] = kwargs.get('inline_css')
4445

4546
model['content']['use_draft_template'] = \
@@ -77,6 +78,10 @@ def _translate_keys(self, **kwargs):
7778
model['content']['attachments'] = self._extract_attachments(
7879
attachments)
7980

81+
inline_images = kwargs.get('inline_images', [])
82+
model['content']['inline_images'] = self._extract_attachments(
83+
inline_images)
84+
8085
return model
8186

8287
def _format_copies(self, recipients, copies):
@@ -176,6 +181,26 @@ def send(self, **kwargs):
176181
name='document.pdf',
177182
filename='/full/path/to/document.pdf'
178183
)
184+
:param inline_images: List of dicts. For example:
185+
186+
.. code-block:: python
187+
188+
dict(
189+
type='image/png',
190+
name='imageCID',
191+
data='base64 encoded string'
192+
)
193+
194+
Replace `data` with `filename` if you want the library to perform
195+
the base64 conversion. For example:
196+
197+
.. code-block:: python
198+
199+
dict(
200+
type='image/png',
201+
name='imageCID',
202+
filename='/full/path/to/image.png'
203+
)
179204
180205
:param str start_time: Delay generation of messages until this
181206
datetime. Format YYYY-MM-DDTHH:MM:SS+-HH:MM. Example:
@@ -192,6 +217,8 @@ def send(self, **kwargs):
192217
:param bool skip_suppression: Whether or not to ignore customer
193218
suppression rules, for this transmission only. Only applicable if
194219
your configuration supports this parameter. (SparkPost Elite only)
220+
:param str ip_pool: The name of a dedicated IP pool associated with
221+
your account
195222
:param bool inline_css: Whether or not to perform CSS inlining
196223
:param dict custom_headers: Used to set any headers associated with
197224
transmission

test/assets/sparkpostdev.png

6.4 KB
Loading

test/test_transmissions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,48 @@ def test_success_send_with_attachments():
171171
os.unlink(temp_file_path)
172172

173173

174+
@responses.activate
175+
def test_success_send_with_inline_images():
176+
current_dir = os.path.abspath(os.path.dirname(__file__))
177+
image_path = os.path.join(current_dir, 'assets', 'sparkpostdev.png')
178+
179+
with open(image_path, "rb") as image:
180+
encoded_image = base64.b64encode(image.read()).decode("ascii")
181+
182+
responses.add(
183+
responses.POST,
184+
'https://api.sparkpost.com/api/v1/transmissions',
185+
status=200,
186+
content_type='application/json',
187+
body='{"results": "yay"}'
188+
)
189+
sp = SparkPost('fake-key')
190+
191+
image_data = {
192+
"name": "sparkpostdev",
193+
"type": "image/png",
194+
"filename": image_path
195+
}
196+
results = sp.transmission.send(inline_images=[image_data])
197+
request_params = json.loads(responses.calls[0].request.body)
198+
content = request_params["content"]["inline_images"][0]["data"]
199+
200+
assert encoded_image == content
201+
assert results == 'yay'
202+
203+
image_data = {
204+
"name": "sparkpostdev",
205+
"type": "image/png",
206+
"data": encoded_image
207+
}
208+
results = sp.transmission.send(inline_images=[image_data])
209+
request_params = json.loads(responses.calls[1].request.body)
210+
content = request_params["content"]["inline_images"][0]["data"]
211+
212+
assert content == encoded_image
213+
assert results == 'yay'
214+
215+
174216
@responses.activate
175217
def test_fail_send():
176218
responses.add(

0 commit comments

Comments
 (0)