Best answer

Conditional logic to attach multiple links or photos from Airtable to Gmail

  • 20 August 2021
  • 4 replies
  • 255 views

Hey all,

 

DATA

I’m building a zap that uses airtable data to populate an email.  The airtable data has photos in one of the fields and can have 1 photo (base case) or many photos.  

 

WHAT I NEED TO DO

I need some sort of conditional logic to say 

if (photos.length === 1) {
attach just one photo // code here or whatever
} else {
attach all the photos // code here or whatever
}

I’ve done this before in sendinblue but they give you access to a “dynamic list” feature where you can provide an array (in my case the photos) and sendinblue will loop through them.

Since I get a url from the airtable data, I’m fine either including link(s) to the photos in the email body

--or--

including the photos as attachments.

 

WHAT I DON’T KNOW HOW TO DO

I know how to link to 1 photo or attach 1 photo but I can’t figure out how to get zapier to create multiple links in the email body OR attach multiple photos IF there are multiple photos

 

If anyone has solved this before let me know!  Greatly appreciated!

icon

Best answer by Troy Tessalone 23 August 2021, 18:20

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 7
Badge +14

Hi @stetson 

Is there a MAX # of photos that can be included from Airtable?

What app are you using to send the email?

Are you sending HTML emails?

There is no max number that CAN be included, but we’ve never used more than 6 photos.

 

I’m sending it straight through the gmail integration in zapier (this is required because we want it to show up in our “sent” label in g-suite so that we can send more messages in the same thread if required).

 

Yes I am sending HTML emails, not plain text.

 

I’d love to be able to loop through an array of values and include the links in the HTML, but as far as I know I don’t have access to any sort of templating language in Zapier that would allow me to do this so there’s not way to parse anything straight in the html.

 

One way I have found that works is to grab the airtable data value “hydrate” from a previous step.  This will pull down and attach ALL the photos in my airtable field as attachments.

this will attach all the photos from an airtable field to my email

 

This is working for now, but if you know how I could do it dynamically in the html that would be cool too.

 

Thanks!

Userlevel 7
Badge +14

Hi @stetson 

For your use, case you’d likely have to use a Code step to split the array of images and format as IMG tags for properly HTML: https://zapier.com/apps/code/help

Check out this help article about the HTML IMG tag: https://www.w3schools.com/tags/tag_img.asp
NOTE: The img tag src url must be a publicly accessible link in order for the image to render properly after the email is sent.

Thanks I’ll give this a look.  Seems like I should be able to loop over a non-constant # of photos in a code step and generate the <img> tags I need.  Then include that in the next step (the email).

 

I’ll mess with it.  

 

Thanks Troy