python-sparkpost
python-sparkpost copied to clipboard
Hosted template and attachments
I have code that works with an inline template and an attachment, and code that works with a hosted template and no attachment.
When I try to use the hosted template with an attachment it is not included. Why is this? Is there a way to have an attachment sent with a hosted template?
I have removed any credentials from the below combined cdoe which should use a hosted template and include the attachment:
from sparkpost import SparkPost
from sparkpost.exceptions import SparkPostAPIException
sparky = SparkPost("SPARKPOST_KEY")
response = sparky.transmissions.send(
from_email={
'email': sender,
'name': "Test Name"
},
recipients=recipient,
template=template_id,
subject=subject_line,
ip_pool='my_mailer',
track_opens=True,
track_clicks=True,
use_draft_template=True,
substitution_data={
'SUBJECT': subject_line,
'ADDRESSEE': addressee_string,
'CONTENT_STRING': content_string,
'SENDER': sender,
'REPLY_TO': reply_to,
'FROM_NAME': from_name
},
attachments=[
{
'type': 'application/vnd.ms-excel',
'name': 'file1.xlsx',
'filename': 'file1.xlsx'
}
]
)
print(response)
If the documentation is up to date, it seems it's not implemented yet.
Attachments Support in the Transmissions API We have added support for attachments using the Transmissions API. Attachments can be any file type or inline images. In a future enhancement, we will include file type validation.
A few notes about this feature:
There is a 20 MB content size limit on each message, including content body and all attachments Attachments are supported with inline templates only. We may include support for attachments with stored templates in the future.