Prepare Emails using Formulas#
You may already know that you can add hyperlink fields in Grist. You may also know about “mailto” links that open a mail program to create a new email message.
Less well-known is that “mailto” links allow pre-filling many parts of the email message. If you use Grist to store contacts, you can essentially create email templates using Grist formulas.
Simple Mailto Links#
The simplest “mailto” link in Grist looks like
mailto:email@example.com. When the column is
set to Text, and its format is set to Hyperlink, it shows as firstname.lastname@example.org.
If you have a table with columns
"Compose Email mailto:%s" % ($Email).
Set its type to Text, and its cell format to Hyperlink:
You’ll get a link in each person’s row, which you can click to start composing an email to that person:
See an example of this in action here: Simple Compose.
Cc, Bcc, Subject, Body#
In addition to opening your email program and filling in the “TO” field, a “mailto” link can fill in other parts of the email, using this format:
All fields are optional. You can specify multiple email addresses for To/Cc/Bcc lists by separating them with commas.
Values of each field should be percent-encoded, which in Python can be done using urllib.parse.quote.
To put this together, this formula will produce a hyperlink to create a pre-filled email:
from urllib.parse import quote return "Compose mailto:%email@example.com&subject=%s&body=%s" % ( quote($Email), quote($Subject), quote($Body))
A live example of this is here: Advanced Compose.
Emailing Multiple People#
Email links are very handy when emailing a group of people, such as students in a class, or people on a certain project.
For instance, if you have a Reference column “Project” that ties a person to a project, then in the table of projects, you can look up all associated people using lookupRecords. You can then build a link to email them as a group:
from urllib.parse import quote people = People.lookupRecords(Project=$id) return "Email Group mailto:%s" % quote(", ".join(people.Email))
You can see this formula at work in Group Compose.
Don’t use this to replace an email marketing platform: since emails use your regular email program, you shouldn’t use it for emailing thousands of people. But for small groups, this can be very convenient.
Configuring Email Program#
If your “mailto” links don’t work, or don’t open your preferred email program, here is an article to help you configure it:
If you need more details, here are some more links:
- To open a desktop program (such as Mail, Thunderbird, etc.) on a Mac: Instructions.
- To open a desktop program (such as Outlook, etc. ) on Windows: Instructions.
- To open Gmail in Chrome and other browsers: Instructions.
- To open webmail (such as Gmail or Yahoo! Mail) or a desktop program in Firefox: Instructions.