al-codaio / events-from-gmail

Create Google Calendar events from sending yourself a Gmail on a mobile device using Google Apps Script.
11 stars 2 forks source link
gmail google-apps-script google-calendar

Create Google Calendar events from sending yourself an email

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.

What this script does

You send yourself an email that looks like this:

send yourself an email with google calendar details

...and a Google Calendar event gets created with all the relevant fields filled out:

create google calendar event from email

Main features

Formatting the email

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:

Optional fields in event

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.

Setup

  1. Create a new Google Apps Script project and replace the default code in the editor with the script. Hit ⌘+S to save the script.

  2. 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.

  3. 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.

  4. 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:

  5. Send yourself a test email to make sure the filter works correctly and the email shows up in your "EventsFromEmail" label.

  6. Back in Google Apps Script, select the getEmail function in the toolbar and click "Run" to run the script for the first time.

  7. Click "Allow" when asked to give Google Apps Script permission to access your Gmail and Google Calendar.

  8. You may get a screen saying Google hasn't verified the app. Click "Advanced" and click the link to continue to use the script:

  9. 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):

Notes & Caveats

Tutorials

Read the full write-up here on why I wrote this script and watch the video tutorial below to setup the script:

create google calendar events from gmail