Attachments in `payload` cause Novu email trigger to fail (500 error)

When attempting to send an email using Novu with an attachment, the request fails with a 500 Internal Server Error. The same code works correctly when the attachments object is removed from the payload.
According to the Novu documentation, attachments should be passed in the payload under the key attachments, but this seems to cause issues in practice. 1. Create an Astro API endpoint that calls Novu’s trigger API.
2. Pass a payload including an attachments object, for example:
const attachment = {
file: Buffer.from(JSON.stringify({ test: "data" })).toString("base64"),
name: "test.json",
mime: "application/json",
};

await fetch(`${import.meta.env.PUBLIC_NOVU_API_URL}`, {
method: "POST",
headers: {
Authorization: `ApiKey ${import.meta.env.PUBLIC_NOVU_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "test-template",
to: {
subscriberId: import.meta.env.PUBLIC_NOVU_SUBSCRIBER_ID,
email: "user@example.com",
},
payload: {
foo: "bar",
attachments: [attachment], // <-- adding this breaks request
},
}),
});
const attachment = {
file: Buffer.from(JSON.stringify({ test: "data" })).toString("base64"),
name: "test.json",
mime: "application/json",
};

await fetch(`${import.meta.env.PUBLIC_NOVU_API_URL}`, {
method: "POST",
headers: {
Authorization: `ApiKey ${import.meta.env.PUBLIC_NOVU_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "test-template",
to: {
subscriberId: import.meta.env.PUBLIC_NOVU_SUBSCRIBER_ID,
email: "user@example.com",
},
payload: {
foo: "bar",
attachments: [attachment], // <-- adding this breaks request
},
}),
});
3. Observe the response:
{
"statusCode": 500,
"message": "Internal server error"
}
{
"statusCode": 500,
"message": "Internal server error"
}
4. Remove the attachments key and re-run — email sends successfully.
9 Replies
Pawan Jain
Pawan Jain3w ago
Hi Shanil

I am Pawan from Novu

Could you please confirm if attachment variable is in form of correct format specified in this doc https://docs.novu.co/platform/integrations/email#sending-email-attachments
file field can be buffee or base64 string
Shanil Sasikumar
Shanil SasikumarOP3w ago
Even though I put the same, I get the same error
{
// base64 format
file: 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNkYPhfz0AEYBxVSF+FAP5FDvcfRYWgAAAAAElFTkSuQmCC',
name: 'blue.png',
mime: 'image/png',
}
{
// base64 format
file: 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAFUlEQVR42mNkYPhfz0AEYBxVSF+FAP5FDvcfRYWgAAAAAElFTkSuQmCC',
name: 'blue.png',
mime: 'image/png',
}
Pawan Jain
Pawan Jain2w ago
Are you using novu cloud? If yes, please share the transactionId from the activity feed page for this workflow trigger
Shanil Sasikumar
Shanil SasikumarOP2w ago
We are running a self-hosted instance of Novu. Are there any specific configurations or environment variables that need to be enabled in our setup to support this functionality? @Pawan Jain Do we need to specify anything in the Novu email template for handling attachments?
Pawan Jain
Pawan Jain2w ago
Yes, you will need to configure a storage service like s3 to send attachments. You will see related environment variables in example env file
Rinshad K Asharaf
Hi @Pawan Jain , So can we refer - https://github.com/novuhq/novu/blob/next/docker/.env.example this file and add the below envs? AWS S3_LOCAL_STACK=$HOST_NAME:4566 S3_BUCKET_NAME=novu-local S3_REGION=us-east-1 AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test and we should use - localstack/localstack service at 4566 locally right ? It worked using minio , Thanks
Shanil Sasikumar
Shanil SasikumarOP2w ago
@Pawan Jain We are receiving a successful response from the API with the following payload:
{
"data": {
"acknowledged": true,
"status": "processed",
"transactionId": "xxx-xxx-xxxx-xxxxx"
}
}
{
"data": {
"acknowledged": true,
"status": "processed",
"transactionId": "xxx-xxx-xxxx-xxxxx"
}
}
However, emails are being delivered. If we send the payload without attachments, for example:
{
"foo": "bar"
}
{
"foo": "bar"
}
It works correctly, and the email is received. But when we include attachments, such as:
{
"foo": "bar",
"attachments": [attachment] // <-- adding this breaks the email delivery
}
{
"foo": "bar",
"attachments": [attachment] // <-- adding this breaks the email delivery
}
The API still returns a successful response, but the email is never sent. Do we need to make any changes in the email template to support attachments? Here’s the current email template:
Dear User,

A new External Assets Assessment (EAA) Intake form has been submitted by {{ userName }}.
Below are the details:

{{ formData }}

Please review the submission and take any necessary actions.

Best regards,
Team XXXX
Dear User,

A new External Assets Assessment (EAA) Intake form has been submitted by {{ userName }}.
Below are the details:

{{ formData }}

Please review the submission and take any necessary actions.

Best regards,
Team XXXX
Novu_Bot
Novu_Bot2w ago
@Shanil Sasikumar, you just advanced to level 1!
Pawan Jain
Pawan Jain2w ago
Shanil

Please check the api and worker service logs, if you see any error? There must be mis configuration of storage service due to which email step is failing

Did you find this page helpful?