Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apps Script to get the users signature

I have created an apps script that will do a simple mail merge using contact details to create a new email draft. It works as expected, but I would like to use the current user's signature in the template.

Documentation on this is dated and incomplete. I created the code below from what I have found, but have had to make a total guess as to what it needs because I can't find the official documentation.

var params;
params = {method:"post",
          contentType: "application/json",
          headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
          muteHttpExceptions:true
        };

var resp = UrlFetchApp.fetch("https://apps-apis.google.com/a/feeds/emailsettings/2.0/{domain}/me/signature", params);
var rCode = resp.getResponseCode();
var rText = resp.getContentText();

This is the response:

rCode = 400
rText = Invalid request URI

What is the correct request URI? Is there a new API for this?

like image 678
davids Avatar asked Jan 18 '17 19:01

davids


1 Answers

Gmail signatures are now accessible from the gmail API. I added a one liner below to get the signature of the current user. I used list instead of get because a user may send email as a different user by default then their logged in account. So I list all accounts and filter out the default one.

https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs

var signature = Gmail.Users.Settings.SendAs.list("me").sendAs.filter(function(account){if(account.isDefault){return true}})[0].signature;
like image 83
Spencer Easton Avatar answered Nov 08 '22 14:11

Spencer Easton