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.

1 comment:

  1. Wynn casino opens in Las Vegas - FilmfileEurope
    Wynn's first air jordan 18 retro men from my site hotel casino in Las Vegas since opening its doors in 1996, Wynn what is the best air jordan 18 retro Las Vegas is 환전 가능 가입 머니 the first hotel on air jordan 18 retro sports the Strip to offer such 스포츠 토토 축구 승무패 벳피스트 놀검소 a large selection of