Skip to content

Hosted template and attachments #197

Description

@ps-jf

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions