A library that provides the ability to manage the signatures of Google Apps users in Google Apps Script.
SignaturesManager for Google Apps Script is a library that provides the ability to manage the signatures of Google Apps users in Google Apps Script.
This library is already published as an Gooogle Apps Script, making it easy to include in your project. To add it to your script, do the following in the Google Apps Script code editor:
For use this library is necessary to use the OAuth2 for Apps Script library.
Example:
function getSignaturesService() {
return OAuth2.createService('signatures')
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setClientId('...')
.setClientSecret('...')
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('https://apps-apis.google.com/a/feeds/emailsettings/2.0/')
.setParam('login_hint', Session.getActiveUser().getEmail())
.setParam('access_type', 'offline');
}
Example:
function showAuthorization() {
var signaturesService = getSignaturesService();
if (!signaturesService.hasAccess()) {
var authorizationUrl = signaturesService.getAuthorizationUrl();,
template = HtmlService.createTemplate(
'<a href="<?= authorizationUrl ?>" target="_blank">Authorize</a>. ' +
'Refresh the page when the authorization is complete.');
template.authorizationUrl = authorizationUrl;
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
} else {
...
}
}
Example:
function authCallback(request) {
var signaturesService = getSignaturesService(),
isAuthorized = signaturesService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
}
return HtmlService.createHtmlOutput('Denied. You can close this tab.');
}
Example:
var signaturesService = getSignaturesService(),
sm = SignaturesManager.create(signaturesService);
var currentSignature = sm.getSignatureByEmail('[email protected]');
sm.setSignatureByEmail('[email protected]', 'This will be my new signature!');