diff --git a/sparkpost/transmissions.py b/sparkpost/transmissions.py index 7f22afe..284b0ed 100644 --- a/sparkpost/transmissions.py +++ b/sparkpost/transmissions.py @@ -40,6 +40,7 @@ def _translate_keys(self, **kwargs): model['options']['transactional'] = kwargs.get('transactional') model['options']['sandbox'] = kwargs.get('use_sandbox') model['options']['skip_suppression'] = kwargs.get('skip_suppression') + model['options']['ip_pool'] = kwargs.get('ip_pool') model['options']['inline_css'] = kwargs.get('inline_css') model['content']['use_draft_template'] = \ @@ -77,6 +78,10 @@ def _translate_keys(self, **kwargs): model['content']['attachments'] = self._extract_attachments( attachments) + inline_images = kwargs.get('inline_images', []) + model['content']['inline_images'] = self._extract_attachments( + inline_images) + return model def _format_copies(self, recipients, copies): @@ -176,6 +181,26 @@ def send(self, **kwargs): name='document.pdf', filename='/full/path/to/document.pdf' ) + :param inline_images: List of dicts. For example: + + .. code-block:: python + + dict( + type='image/png', + name='imageCID', + data='base64 encoded string' + ) + + Replace `data` with `filename` if you want the library to perform + the base64 conversion. For example: + + .. code-block:: python + + dict( + type='image/png', + name='imageCID', + filename='/full/path/to/image.png' + ) :param str start_time: Delay generation of messages until this datetime. Format YYYY-MM-DDTHH:MM:SS+-HH:MM. Example: @@ -192,6 +217,8 @@ def send(self, **kwargs): :param bool skip_suppression: Whether or not to ignore customer suppression rules, for this transmission only. Only applicable if your configuration supports this parameter. (SparkPost Elite only) + :param str ip_pool: The name of a dedicated IP pool associated with + your account :param bool inline_css: Whether or not to perform CSS inlining :param dict custom_headers: Used to set any headers associated with transmission diff --git a/test/assets/sparkpostdev.png b/test/assets/sparkpostdev.png new file mode 100644 index 0000000..604a700 Binary files /dev/null and b/test/assets/sparkpostdev.png differ diff --git a/test/test_transmissions.py b/test/test_transmissions.py index 163ad85..2d61977 100644 --- a/test/test_transmissions.py +++ b/test/test_transmissions.py @@ -171,6 +171,48 @@ def test_success_send_with_attachments(): os.unlink(temp_file_path) +@responses.activate +def test_success_send_with_inline_images(): + current_dir = os.path.abspath(os.path.dirname(__file__)) + image_path = os.path.join(current_dir, 'assets', 'sparkpostdev.png') + + with open(image_path, "rb") as image: + encoded_image = base64.b64encode(image.read()).decode("ascii") + + responses.add( + responses.POST, + 'https://api.sparkpost.com/api/v1/transmissions', + status=200, + content_type='application/json', + body='{"results": "yay"}' + ) + sp = SparkPost('fake-key') + + image_data = { + "name": "sparkpostdev", + "type": "image/png", + "filename": image_path + } + results = sp.transmission.send(inline_images=[image_data]) + request_params = json.loads(responses.calls[0].request.body) + content = request_params["content"]["inline_images"][0]["data"] + + assert encoded_image == content + assert results == 'yay' + + image_data = { + "name": "sparkpostdev", + "type": "image/png", + "data": encoded_image + } + results = sp.transmission.send(inline_images=[image_data]) + request_params = json.loads(responses.calls[1].request.body) + content = request_params["content"]["inline_images"][0]["data"] + + assert content == encoded_image + assert results == 'yay' + + @responses.activate def test_fail_send(): responses.add(