Email attachments
Learn more about how to send emails with attachments in Knock.
How attachments work in Knock#
- Set an attachment key in your email template to tell Knock how to resolve attachments you send in the data payload of your trigger call. To set an attachment key, click the gear icon (⚙️) at the top of the email template editor, then set your desired key under the "Attachment key" field. This key will default to
attachments
if not specified. - Include one or more attachment objects in the
data
payload of your trigger call, under the configured attachment key. Each attachment object should have the content of the file to be attached as a base64 encoded value. - Knock automatically adds any attachments included in the attachment key of your trigger call to the emails sent by your email provider 🎉.
The attachment object#
Every attachment you send to Knock in your data
payload should include the following properties (those marked with an *
are required):
Note: each attachment object must be less than 10mb, but you should confirm whether your email provider has a lower limit.
Sending attachments in your trigger call#
Once you've specified your attachment key in your email template, the last step is to send the data along to Knock. Remember that you need to base64 encode the contents of the file.
Note: you can send multiple attachments for an email by including an array of attachment objects under the attachment key in your data payload.
Sending a different attachment per recipient#
If you need to send a different attachment per recipient in a workflow then you'll need to make one trigger call per recipient, such that the data payload is unique to that recipient.
Referencing attachment files inline#
If you're using SendGrid or Postmark as your email provider, you can reference attachment files inline in your email template by providing a content_id
property on the attachment object you send in your trigger call. Adding a content_id
to the attachment embeds it in the email as an inline attachment, which you can reference in your template using the cid:
prefix and the content_id
value.
Previewing messages with attachments#
The Knock dashboard does not currently support previewing the attachment files that are sent with your email messages. This means that you'll need to send a test message (via the workflow test runner or the API) to your own email inbox to see what the attachment(s) will look like.
This limitation applies to both regular attachment files and inline attachments. Any images that are sent as inline attachments will not be viewable in the dashboard.