Skip to main content

Send Email Action Conditionally


Is it possible to only complete an action based on the output of a previous action? I would like to run a script when a field is updated, but I want to send an email based on the output of the script. If the script runs and doesn’t find any conflicts I don’t want to send an email.


In this case I don’t really see a way to break out of an automation or send an email inside a script other than using outside API calls.


How would you accomplish this? Would Airtable throw errors if I just put in a blank email in the to: field so that the step is executed, but it doesn’t actually send to anyone?

21 replies

kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • October 31, 2020

Use two automations and an email table. Have the first automation run the current script. If there should be an email, have the script create a record in the email table. Then have a second automation watch to email table and actually send the email.


  • Author
  • Known Participant
  • 21 replies
  • October 31, 2020
kuovonne wrote:

Use two automations and an email table. Have the first automation run the current script. If there should be an email, have the script create a record in the email table. Then have a second automation watch to email table and actually send the email.


That is a nice workaround. There are just so many tables in the base already. I wish you could hide tables or communicate between bases more seamlessly.


Thanks @kuovonne you seem to always have the answer lol.


  • Inspiring
  • 3264 replies
  • October 31, 2020
Faculty_Schedul wrote:

That is a nice workaround. There are just so many tables in the base already. I wish you could hide tables or communicate between bases more seamlessly.


Thanks @kuovonne you seem to always have the answer lol.



One more idea - send the unnecessary email to a dead-end address.


  • Author
  • Known Participant
  • 21 replies
  • November 5, 2020
Bill_French wrote:

One more idea - send the unnecessary email to a dead-end address.


Yea that is a good idea. I was wondering what was better dead-end address or just a blank address. I assume Airtable might give an error if the email address is blank, but I think it would just show a failed automation run or maybe I can just handle the error.


kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • November 5, 2020
Bill_French wrote:

One more idea - send the unnecessary email to a dead-end address.



How would you decide what email address to use and where would you store it? Airtable automations currently don’t have branching, so the dead-end email address would need to exist in the same location as the valid email addresses. You could use another formula field for this, but adding fields creates clutter too.



Do you want to include the output of the script in the email? For example, does the script generate text that you want in the email? If so, I believe that the automation will use the field values that existed at trigger time, not any values that were updated by the script after the automation was triggered.


  • Inspiring
  • 3264 replies
  • November 5, 2020
kuovonne wrote:

How would you decide what email address to use and where would you store it? Airtable automations currently don’t have branching, so the dead-end email address would need to exist in the same location as the valid email addresses. You could use another formula field for this, but adding fields creates clutter too.



Do you want to include the output of the script in the email? For example, does the script generate text that you want in the email? If so, I believe that the automation will use the field values that existed at trigger time, not any values that were updated by the script after the automation was triggered.



Why?


let emailAddress = (field.address === null) ? "deadend@domain.com" : field.address;


kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • November 5, 2020
Bill_French wrote:

Why?


let emailAddress = (field.address === null) ? "deadend@domain.com" : field.address;



Because the code that you wrote is code. It is not something that you can put in the “to” field when configuring a email action in Airtable.


  • Inspiring
  • 3264 replies
  • November 5, 2020
kuovonne wrote:

Because the code that you wrote is code. It is not something that you can put in the “to” field when configuring a email action in Airtable.



Doesn’t the email action have the ability to utilize the results of a previous script process in the action?


kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • November 5, 2020
Bill_French wrote:

Doesn’t the email action have the ability to utilize the results of a previous script process in the action?


The email action in Airtable automations is a completely different action from the scripting action. As far as I can tell, scripting actions have no outputs that are accessible in the automation chain.


  • Inspiring
  • 3264 replies
  • November 5, 2020
kuovonne wrote:

The email action in Airtable automations is a completely different action from the scripting action. As far as I can tell, scripting actions have no outputs that are accessible in the automation chain.



Hmmm, I use them all the time.



kuovonne
Forum|alt.badge.img+17
  • Brainy
  • 5987 replies
  • November 6, 2020
Bill_French wrote:

Hmmm, I use them all the time.




Super cool! I must have missed this in the documentation. This is awesome. Thanks for pointing it out!


  • Inspiring
  • 3264 replies
  • November 6, 2020
kuovonne wrote:

Super cool! I must have missed this in the documentation. This is awesome. Thanks for pointing it out!



Old dog teaching new dog old trick? :winking_face:


  • Inspiring
  • 18 replies
  • December 7, 2020
Bill_French wrote:

Hmmm, I use them all the time.



Hi @Bill.French I am actually struggling quite a bit with the idea of composing a properly formatted multi-line email body in script as markdown and passing that over to the gmail automation - especially for a proper signature including logos and such.

Could you share any snippets? How do i compile a email body with multiple line breaks and pass it to output.set?


Any help would be much appreciated!


Thanks!


  • Inspiring
  • 3264 replies
  • December 7, 2020
Martin_Kranz wrote:

Hi @Bill.French I am actually struggling quite a bit with the idea of composing a properly formatted multi-line email body in script as markdown and passing that over to the gmail automation - especially for a proper signature including logos and such.

Could you share any snippets? How do i compile a email body with multiple line breaks and pass it to output.set?


Any help would be much appreciated!


Thanks!



This is thee best you can do with regard to email messages because Airtable has chosen to deeply sanitize all content in email bodies.



Oddly, Airtable has no issue with embedding their own brand and logo, while the rest of us are left to create brandless, mundane, and completely boring notifications. For my clients, I avoid [Airtable’s] email automation like I avoid Covid. Instead, I opt for 100% control through Gmail using Google Apps Script and tight integration processes.


The trick to control newlines and embedded (but extremely limited) markdown content in Airtable is to compose the entire message in a script variable and use it – AND ONLY IT – in the message body.


// compose a markdown email message...



let thisMessage = "Hi Martin!\n\n";



thisMessage += "This message includes an embedded link to [Global Technologies Corporation](http://globaltc.com), my website."



thisMessage += "Tux, the [Linux mascot](https://drive.google.com/file/d/1NO5DEtDp8L59UHmhqQj55jlyBK_k31yZ/view?usp=sharing) \n\n";



thisMessage += "Cheers!\n\nbf..."



output.set("message",thisMessage)

  • Inspiring
  • 18 replies
  • December 7, 2020
Bill_French wrote:

This is thee best you can do with regard to email messages because Airtable has chosen to deeply sanitize all content in email bodies.



Oddly, Airtable has no issue with embedding their own brand and logo, while the rest of us are left to create brandless, mundane, and completely boring notifications. For my clients, I avoid [Airtable’s] email automation like I avoid Covid. Instead, I opt for 100% control through Gmail using Google Apps Script and tight integration processes.


The trick to control newlines and embedded (but extremely limited) markdown content in Airtable is to compose the entire message in a script variable and use it – AND ONLY IT – in the message body.


// compose a markdown email message...



let thisMessage = "Hi Martin!\n\n";



thisMessage += "This message includes an embedded link to [Global Technologies Corporation](http://globaltc.com), my website."



thisMessage += "Tux, the [Linux mascot](https://drive.google.com/file/d/1NO5DEtDp8L59UHmhqQj55jlyBK_k31yZ/view?usp=sharing) \n\n";



thisMessage += "Cheers!\n\nbf..."



output.set("message",thisMessage)

@Bill.French You are my personal hero of the day (du jour), I am much happier using the gmail integration if I can control line breaks, logos, links this way. Thanks a ton, you’ve made my day!


  • Inspiring
  • 18 replies
  • December 7, 2020
Martin_Kranz wrote:

@Bill.French You are my personal hero of the day (du jour), I am much happier using the gmail integration if I can control line breaks, logos, links this way. Thanks a ton, you’ve made my day!


Wait a second, a follow-up question, would you be happy to share a similar code example that you pass to gmail instead? Would passing a public image (logo) be possible via the native gmail module in automations or is App Scripts really the only way @Bill.French?


  • Inspiring
  • 3264 replies
  • December 7, 2020
Martin_Kranz wrote:

@Bill.French You are my personal hero of the day (du jour), I am much happier using the gmail integration if I can control line breaks, logos, links this way. Thanks a ton, you’ve made my day!



The day is still young. I hope the bar is far higher than the utterances that emerge from my pie-hole. :winking_face:


  • Inspiring
  • 3264 replies
  • December 7, 2020
Martin_Kranz wrote:

Wait a second, a follow-up question, would you be happy to share a similar code example that you pass to gmail instead? Would passing a public image (logo) be possible via the native gmail module in automations or is App Scripts really the only way @Bill.French?



This is a deep topic that requires a host of supporting stuff and a few hours of documentation, so no. I am trying to get my team to package exactly such an example solution and publish it on Gumroad with a customer-decides-the-price model (like shareware). We hope to toss that over the way in a week or so.


Bear in mind, that I promote this as a remedy to lacklustre email and reporting support in Airtable for – and only for - processes that require pixel-precise reporting or communications. When brand and image matters, you’re not likely to achieve your objectives with off-the-shelf no/low-code automation crap. And I mean “automation crap” with the greatest respect; no company can do everything for everyone. There are many ways to achieve good communications from no-code platforms so my approach is not ideal in every situation. One reason I get calls to build this better crap is there are mitigating issues such as additional integrations with other SDKs, email analytics, email steps where human triage is required, etc.


The general approach is:



  1. When an email needs to be sent, use an Airtable action script to call a webhook.

  2. The webhook is a server running in your Gmail account as a script web service (Google Apps Script supports this for free).

  3. Your custom webhook service hears the call and uses the Airtable API to call back to get all the data for the email message.

  4. The script then binds the data/images and anything you desire using HTML with the message template and creates either a draft in your outbox that you can review/edit and send, or sends it immediately.

  5. Once the message is dispatched, the script uses the Airtable API to update the Airtable record relevant to the email event.


Might look like this…




Sadly, I believe this is not possible in Airtable’s native tools. But, it may be possible with Integromat. @ScottWorld can probably tell us.


ScottWorld
Forum|alt.badge.img+20
  • Brainy
  • 8710 replies
  • December 7, 2020
Bill_French wrote:

This is a deep topic that requires a host of supporting stuff and a few hours of documentation, so no. I am trying to get my team to package exactly such an example solution and publish it on Gumroad with a customer-decides-the-price model (like shareware). We hope to toss that over the way in a week or so.


Bear in mind, that I promote this as a remedy to lacklustre email and reporting support in Airtable for – and only for - processes that require pixel-precise reporting or communications. When brand and image matters, you’re not likely to achieve your objectives with off-the-shelf no/low-code automation crap. And I mean “automation crap” with the greatest respect; no company can do everything for everyone. There are many ways to achieve good communications from no-code platforms so my approach is not ideal in every situation. One reason I get calls to build this better crap is there are mitigating issues such as additional integrations with other SDKs, email analytics, email steps where human triage is required, etc.


The general approach is:



  1. When an email needs to be sent, use an Airtable action script to call a webhook.

  2. The webhook is a server running in your Gmail account as a script web service (Google Apps Script supports this for free).

  3. Your custom webhook service hears the call and uses the Airtable API to call back to get all the data for the email message.

  4. The script then binds the data/images and anything you desire using HTML with the message template and creates either a draft in your outbox that you can review/edit and send, or sends it immediately.

  5. Once the message is dispatched, the script uses the Airtable API to update the Airtable record relevant to the email event.


Might look like this…




Sadly, I believe this is not possible in Airtable’s native tools. But, it may be possible with Integromat. @ScottWorld can probably tell us.



Yes, all of this is possible with Integromat. In fact, I have many of my clients using Integromat for this, due to the limitations of Airtable’s email automations.


@Martin_Kranz If you have a budget for this project and you’d like to hire an Airtable consultant & Registered Integromat Partner to help you create this, please feel free to contact me through my website at ScottWorld.com.


  • Inspiring
  • 18 replies
  • December 7, 2020
ScottWorld wrote:

Yes, all of this is possible with Integromat. In fact, I have many of my clients using Integromat for this, due to the limitations of Airtable’s email automations.


@Martin_Kranz If you have a budget for this project and you’d like to hire an Airtable consultant & Registered Integromat Partner to help you create this, please feel free to contact me through my website at ScottWorld.com.


Hey @ScottWorld unfortunately, I am kinda restricted in terms of budget - also not really a programmer which is making my life quite hard right now but i like a challenge (or so i tell myself). I am currently having a similar setup with Zapier but wanted to avoid 3rd party solutions actually, am tempted to just try triggering a simple send-email scenario with basic headers and copy from within the scripting block instead.


Thanks both for your help!!!


  • Author
  • Known Participant
  • 21 replies
  • December 22, 2020
Bill_French wrote:

This is a deep topic that requires a host of supporting stuff and a few hours of documentation, so no. I am trying to get my team to package exactly such an example solution and publish it on Gumroad with a customer-decides-the-price model (like shareware). We hope to toss that over the way in a week or so.


Bear in mind, that I promote this as a remedy to lacklustre email and reporting support in Airtable for – and only for - processes that require pixel-precise reporting or communications. When brand and image matters, you’re not likely to achieve your objectives with off-the-shelf no/low-code automation crap. And I mean “automation crap” with the greatest respect; no company can do everything for everyone. There are many ways to achieve good communications from no-code platforms so my approach is not ideal in every situation. One reason I get calls to build this better crap is there are mitigating issues such as additional integrations with other SDKs, email analytics, email steps where human triage is required, etc.


The general approach is:



  1. When an email needs to be sent, use an Airtable action script to call a webhook.

  2. The webhook is a server running in your Gmail account as a script web service (Google Apps Script supports this for free).

  3. Your custom webhook service hears the call and uses the Airtable API to call back to get all the data for the email message.

  4. The script then binds the data/images and anything you desire using HTML with the message template and creates either a draft in your outbox that you can review/edit and send, or sends it immediately.

  5. Once the message is dispatched, the script uses the Airtable API to update the Airtable record relevant to the email event.


Might look like this…




Sadly, I believe this is not possible in Airtable’s native tools. But, it may be possible with Integromat. @ScottWorld can probably tell us.


This is great stuff Bill. Thanks for adding this.


I would just to advocate for Google Apps Script. It is so nice to work with. There are only a few issues I have run into that make me scratch my head. I have to say I really love Google Apps Script they have a wonderful API that lets you do a ton of stuff. I’ve used it to create a form that automatically generates Google Forms based on user input with short link and QR Codes (from external API) automatically and sends out HTML emails letting people know when submissions have started.


Reply