Custom Button Script

Hello everyone! I’m trying out the Button field and I want to be able to send a templated email to a static address on button press. I don’t have a paid account so I can’t use the SendGrid action and was trying to recreate it in a scripting block using SMTP https://www.smtpjs.com/

I ran into issues trying to use react/html tags in the scripting block, is this possible? Is there a better way to achieve the same thing? Thanks

1 Like

You can do this but it won’t physically send. It will open the email client and then you’d have to hit send.

Button field actions

Open URL

This action will open a link where the URL can be based on values from your record. If the URL is for a link in the same Airtable base, clicking will send you to the URL in the same window. For all other URLs, a new window will open.

Additional fields for the URL option are:

  • URL formula: This uses the same formula syntax as the existing formula field and supports using cell values from other fields (usually some sort of ID).

Integrating with other systems becomes much easier with this button as you can click the button to connect to the specific item in the other system. Here are some examples to get you going!

Send an email

Generic email provider

"mailto:" & ENCODE_URL_COMPONENT(Email) & "?subject=" & ENCODE_URL_COMPONENT(Subject) & "&body=" & ENCODE_URL_COMPONENT(Body)

Gmail

"https://mail.google.com/mail/u/0/?view=cm&to="
& ENCODE_URL_COMPONENT(Email) & "&su=" & ENCODE_URL_COMPONENT(Subject) & "&body=" & ENCOD
2 Likes

Anyone considering SmtpJS (whether in an Airtable product or anywhere else) should think carefully about the privacy implications. The library operates by sending your message to the owner of smtpjs.com, who apparently sends an e-mail on your behalf. You’ll have to trust that they respect your privacy, though it’s concerning that their website makes no claims about how they use your data.

That said, it’s still worth discussing this approach because it’s an opportunity to learn about the Scripting Block and web development in general.

The Scripting Block does not support JSX, so to output information, you’ll have to rely on the API methods it provides for this purpose. The Scripting Block’s documentation is available here.

The task of sending e-mail is unrelated. You may be able to use SmtpJS, but because your script must be fully self-contained, you’ll have to copy and paste the library’s source code.

This may not work, though. The Scripting Block’s environment is not the same as the typical web browser environment for which SmtpJS was likely designed. The project’s documentation is minimal, so it’s hard to predict whether or not the library will function in this context (or whether it will continue to do so in future releases).

1 Like