version 0.0.1
Muzammil Shahbaz
This small program reads preset birthday events from your Google calendar everyday and sends 'Happy Birthday' emails from your side.
- Node.js installed.
- The npm package management tool (comes with Node.js).
- Google account.
The program uses OAuth 2.0 authorization framework to access your Google Calendar events and Gmail settings. You have to activate Gmail API and Calendar API from Google Developers Console. The step by step process is explained by Google as follows:
- Open the Google Developers Console page.
- From the project drop-down, choose 'Create a new project', enter a name for the project, e.g., 'Birthday Email Sender'.
- On the Credentials page, select Create credentials, then select OAuth client ID.
- Under Application type, choose Web application.
- Under Authorized redirect URIs, add https://developers.google.com/oauthplayground
- Click Create.
- On the page that appears, take note of the Client ID
and Client Secret. Save them into
config/client_secret.json
for keys client_id and client_secret respectively.
- Go to the OAuth2 Playground.
- Click the gear icon in the upper right corner and check the box labeled 'Use your own OAuth credentials' (if it isn't already checked). Make sure that:
- OAuth flow is set to Server-side.
- Access type is set to Offline (this ensures you get a refresh token and an access token, instead of just an access token).
- Enter the OAuth2 client ID and OAuth2 client secret you obtained above.
- In the section labeled 'Step 1 - Select & authorize APIs', select
- https://www.googleapis.com/auth/calendar.readonly under Calendar API v3
- https://mail.google.com/ under Gmail API v1
- Click Authorize APIs
- If prompted, log in to the account to which you want to grant access and authorization. Otherwise, allow the app to access Gmail and Calendar.
- In the tab labeled 'Step 2 - Exchange authorization code for tokens', you should now see an Authorization code. Click 'Exchange authorization code' for tokens.
- If all goes well, you should see the Refresh token and Access token filled in for you (you may have to re-expand 'Step 2 - Exchange authorization code' for tokens to see these values)
- Copy the Refresh token and save into
config/client_secret.json
for the key refresh_token.
- Open
config/email_message_settings.json
and customize message to suit your taste. - Open
config/client_secret.json
and edit the user key to your Google user account.
You can setup as many birthday events using the following steps:
- Open Google Calendar in your account
- Create event as follows
- Add title with prefix .bd followed by your friend's name, like this:
bd. John
The prefix is important. This is how the app identifies the event as a birthday event.
2. Add description with the name of your friend how you want to address the person, e.g., Jonny and enter the email address in the next line, like this:
Jonny
Run the app with the command npm start
.
This app will read the events for today, and send email if any birthday event is found. Then it will check for events every day at 10am local time.