Friday, January 10, 2014

Gmail Inbox Notification Widget

I wanted to display my Gmail Inbox unread message count on my personal web page on Google Sites, so I made a tiny Google Apps Script widget to do this.

The code turned out very simple.
function doGet() {
  return HtmlService.createTemplateFromFile('page')

function getInboxUnreadCount() {
  return GmailApp.getInboxUnreadCount();

<style type="text/css">
#refresh { color: blue; text-decoration: underline; }
#refresh:hover { cursor: pointer; }

<div id="inbox">
Inbox (<span id="count">...</span>)
<span id="refresh">refresh</span>

<script src="//"></script>
function check() {
    .withSuccessHandler(function(result) {
      $('#inbox').toggleClass('unread', result > 0);
  check.timer = setTimeout(check, 600000);

$(function() {


The getInboxUnreadCount() function needed to be run from the script editor to grant the needed permissions to the script, after that it worked from my personal home page.

No comments:

Post a Comment