This Google Apps Script allows you to create a Google Calendar event by sending yourself an email in Gmail. Unlike Gmail's current feature to create Google Calendar events, this script allows you to be on a mobile device.
You send yourself an email that looks like this:
...and a Google Calendar event gets created with all the relevant fields filled out:
- Switch between U.S. (m/d/y) and non-U.S. (d/m/y) date formats in the subject line of your email
- Create all-day and multi-day events
- Invite guests and add to the description of the event by writing in the body of the email (see Optional fields in event below)
The only required content you need to include in the email is the subject line. The minimum info you need is the event title and the date (separated by a comma). Some examples on what you could write in the subject line:
Schedule appointment, 9/3, 3PM
: An event with the title "Schedule appointment" gets created on September 3rd at 3:00PMSchedule appointment, 9/3
: An all-day event with the title "Schedule appointment" gets created on September 3rdSchedule appointment, 9/3-9/5
: A multi-day event with the title "Schedule appointment" gets created from September 3rd to September 5th
If you want to invite guests to your event and know their email addresses, you simply write "cc: johndoe@gmail.com, janedoe@gmail.com" as the first line in the body of the email (multiple emails need to be separated by a comma). To add a description to the event, just write the description in the second line of the email. So if the body of your email looks like this:
cc: johndoe@gmail.com, janedoe@gmail.com
Need to schedule an appointment with John and Jane
The Google Calendar event will invite johndoe@gmail.com and janedoe@gmai.com as guests to your event and "Need to schedule an appointment with John and Jane" gets added to the descriptoin of the event.
- Create a new Google Apps Script project and replace the default code in the editor with the script. Hit ⌘+S to save the script.
- Create a Gmail label called "EventsFromEmail" (this is the
GMAIL_LABEL
variable in line 8). If you call the label something else, just make sure to change this line of the script. - The
DEFAULT_EVENT_TIME
in line 9 is 30 minutes (change if necessary). Also decide if your date format is "US" or "ROW" (rest of the world) in line 10. - Setup a Gmail filter so that all emails you send to yourself automatically get labeled "EventsFromEmail" and skip the inbox (but still stay unread). The recipient email address should use the + trick in Gmail to setup your Gmail filter. For instance, I set up a filter so that all emails sent to "al+cal@coda.io" go to my "EventsFromEmail" label:
- Send yourself a test email to make sure the filter works correctly and the email shows up in your "EventsFromEmail" label.
- Back in Google Apps Script, select the
getEmail
function in the toolbar and click "Run" to run the script for the first time. - Click "Allow" when asked to give Google Apps Script permission to access your Gmail and Google Calendar.
- You may get a screen saying Google hasn't verified the app. Click "Advanced" and click the link to continue to use the script:
- Set up a time-driven trigger so that the
getEmail
function runs every 10 minutes, 30 minutes, or whatever interval suits you (I set mine to every 15 minutes):
- If you add a time for the event in the subject line, it needs to have "AM" or PM" appended to the time
- Events get created based on the timezone setting of your Google Apps Script (which defaults to the timezone of your computer)
- If you change timezones, you may need to update the
appscript.json
file with the new timezone you're in. See this Wikipedia article (specifically the "TZ database name" column) for the proper formatting of timezone names.
Read the full write-up here on why I wrote this script and watch the video tutorial below to setup the script: