I am ready to share a little project around
Gmail that I have been working on this weekend. The idea is that you
can turn your Twitter Timeline into a Gmail Notifier and get notified
(via tweets) as soon as new email messages arrive in your mailbox.
And since you can link Twitter to your phone number, you can even get SMS text alerts for new Gmail messages on your mobile phone with the help of Twitter. There’s no programming required and you can be up and running in 5 minutes.
My solution (see source code) uses OAuth with Google Apps Script to link your Gmail and Twitter accounts so you don’t have to share your passwords with anyone. You have a Google Docs spreadsheet that monitors your Gmail mailbox in the background, say, every 5 minutes. As soon as it finds any new message(s) in your mailbox, it sends out a tweet using your own Twitter app. That’s the overall picture but here’s how you can implement it:
One more thing. In the default setup, the Google Script watches your Gmail Inbox for all incoming mails and tweets as soon as it encounters any new messages in the mailbox.
If this results in too many tweets (or SMS text messages), you can specify a different Gmail search filter and thus receive notifications only for messages that you care about. You need to change the value of GMAIL_SEARCH_STRING in line #18.
And since you can link Twitter to your phone number, you can even get SMS text alerts for new Gmail messages on your mobile phone with the help of Twitter. There’s no programming required and you can be up and running in 5 minutes.
Connect Gmail and Twitter through Google Docs
Gmail provide an RSS feed of your mailbox but the big problem is that if you have to auto-publish this RSS feed to Twitter, you’ll have to supply your Google account credentials in plain text. That’s not done.My solution (see source code) uses OAuth with Google Apps Script to link your Gmail and Twitter accounts so you don’t have to share your passwords with anyone. You have a Google Docs spreadsheet that monitors your Gmail mailbox in the background, say, every 5 minutes. As soon as it finds any new message(s) in your mailbox, it sends out a tweet using your own Twitter app. That’s the overall picture but here’s how you can implement it:
Step A: Create a new Twitter App for Gmail
- Go to twitter.com/signup and create a new Twitter account for your Gmail Inbox – mine is called myGmailInbox.
- Confirm your email address, then open the Twitter settings page and check the option “Protect My Tweets” and uncheck the option “Let others find me by my email address.” This is necessary because you don’t want search engines, or any other Twitter user, to see your Gmail tweets even if the tweets will only have the message subject.
- Go to dev.twitter.com, sign-in using your new Twitter account and use the following values to create a New Twitter App. [Name=Gmail; Description=Gmail Bot; Website=http://goo.gl/ldAXX; Callback URL=https://spreadsheets.google.com/macros]
- Make sure there are no empty spaces in the URL fields else Twitter may give an “Invalid URL format” warning. Accept the terms and conditions, fill in the CAPTCHA and submit the form to create your first Twitter application.
- Next go to the Settings Tab of your Twitter Application and change the “Access” mode from “Read only” to “Read and Write” since we want to publish tweets from Google Docs.
- Save the Settings, then switch to the tab that says OAuth Tool and make a note of the Consumer Key and the Consumer Secret Key.
Step B: Link Google Docs and Twitter
- Go to Google Docs and make a copy of this spreadsheet in your own Docs account.
- From Tools –> Script Editor, replace the values of TWITTER_CONSUMER_KEY and TWITTER_CONSUMER_SECRET with their actual values.
- Go to Resources –> Current Script’s triggers and create a new Time-driven event for “sendTweet” that triggers every 5 minutes.
- Save the trigger and then click Authorize (Grant Access) so that this script can automatically read your Gmail inbox at set intervals to check for new mails.
- Go to Run –> SendTweet and it should display another “Authorization Required” message from Twitter. Click Authorize –> Authorize App to allow Google Apps Script publish tweets to your Twitter Gmail account.
Step C: Follow Gmail on Twitter
- Log in to your old Twitter account and send a follow request to your new Gmail account on Twitter.
- Log in to your new Gmail account and approve the “follow request.”
- And we are done. You should now see tweets for new Gmail messages, as they arrive, in your main timeline.
Get SMS Alerts for New Gmail
Should you wish to receive SMS alerts on your mobile phone for new Gmail messages, just open the Twitter profile page of your Gmail bot and turn on Mobile Notifications. This will obviously work only if you have connected (and verified) your mobile phone with your main Twitter account.One more thing. In the default setup, the Google Script watches your Gmail Inbox for all incoming mails and tweets as soon as it encounters any new messages in the mailbox.
If this results in too many tweets (or SMS text messages), you can specify a different Gmail search filter and thus receive notifications only for messages that you care about. You need to change the value of GMAIL_SEARCH_STRING in line #18.