Skip to main content

Send an email with CSV attachment using Sendgrid

You can use the Sendgrid block Send email with CSV attachment, to send an email that has one CSV file attached.

This block has an input Attachment CSV Content, which should be an array of objects. The keys of each object are ignored, and the values are placed in the CSV line.

Example input:

[
    {
       "ignored_key 1": "csv value 1",
       "ignored_key 2": 123
    },
    {
       "second_line_ignored_key 3": "csv value 3"
    }
]

This will result in following CSV content:

csv value 1, 123 csv value 3

Here's an example automation that loops over contacts from a CRM. We use a variable of type Object to define the values that will be placed in one CSV line:

Defining values.

an automation consisting of a Start block, a List Contacts block with two Variable blocks in its loop, and a Send Email With CSV Attachment block. The first Variable block is selected. The variable is an object with a Key of column1 and a Value of List Contacts > Item > First Name.

Remember, the keys (column1, column2 and column3 above) are ignored. We add this object to a second variable of type list:

Adding an object to a list.

As above, but the second Variable block is selected. The variable is a list.

This list becomes the input of the Sendgrid block:

Sending an email with an attached list.

As above, but the Send Email With CSV Attachment block is selected. The attachment is the CSV list created by the previous variable.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!