Gmail Signatures

At work, I’ve got a “pretty” footer for my signature on Gmail. I have this, because I’m a geek, and it takes a little bit of general geekery to link a profile picture on a gmail signature. For my signature, I use Gravatar to have an “externally hosted” profile picture, but for colleagues at work, I couldn’t quite sit down with each of them and walk them through the process. So, they had to sit on and watch my signature with envy.

Cut to Friday, when I had a bit of spare time and a brainwave.

At work (much like at home) we use GMail to provide Office/Collaboration/etc functionality. Part of the GSuite is Google Apps Script.

After a bit of jiggery pokery, I managed to knock up a script to enable your average Joe on the street to embed their Google profile image into their GMail signature.

The tricky part, aparently, is getting the “externally hosted” Google profile picture.

  var theUser = DriveApp.getRootFolder().getOwner();
  var thePhotoUrl = theUser.getPhotoUrl().replace("=s64", "=s128");

That said, the solution turned out fairly straightforward in the end (although it does mean you have to give the app some scary permissions!) (Update – fixed, see end of post)

I’ve pushed all the code up to the smileham/gapps-gmail-signature GitHub repository, and you can see the script in action by clicking on this Gmail Signature link (be aware, it asks for full Google Drive permissions to get the profile image, and then the Gmail permission to set the signature).

Update 18/11/2019

It has been pointed out by the Information Security Officer at work, that it may not be best practice to have regular staff get in the habit of approving a script which can have total access to your Google Drive (fair enough!). So I’ve gone back to the drawing board and updated the script to use the Google “People API” instead, which requires far less permissions, but is more of a faff to use!

var person = People.People.get("people/me", {personFields: 'names,photos'});
  theHTML.photoUrl =[0].url.replace("=s100","=s128");
  theHTML.userName = person.names[0].displayName;

Using this “Advanced API” now means that permissions need to be set manually within the Google Apps script, but does limit the damage that could be done!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.