Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:33:46+00:00 2026-06-04T19:33:46+00:00

I would like to use the Email Settings API with Apps Script to manage

  • 0

I would like to use the Email Settings API with Apps Script to manage all users signatures on a Google Site. I have used Documents Data APIs before with 2-legged OAuth and it worked just fine. I am currently stuck on the authentication step for Email Settings API.

Code example:

// Setup OAuthServiceConfig
var oAuthConfig = UrlFetchApp.addOAuthService("signature");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken"); 
//I left scope empty to gain access to all APIs would this scope work scope=https://apps-apis.google.com/a/feeds/emailsettings/2.0/
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setConsumerKey("domain.com");
oAuthConfig.setConsumerSecret("consumerSecret");

// Setup optional parameters to point request at OAuthConfigService.  The "signature"
// value matches the argument to "addOAuthService" above.
var options =
{
  "method" : method,
  "oAuthServiceName" : "signature",
  "oAuthUseToken" : "always"
};

var result = UrlFetchApp.fetch("https://apps-apis.google.com/a/feeds/emailsettings/2.0/"+domainName+"/"+userName+"/signature", options);
Logger.log(result);

I get this error: “Unexpected Error (line 37)” which is
var result = UrlFetchApp.fetch(“https://apps-apis.google.com/a/feeds/emailsettings/2.0/”+domainName+”/”+userName+”/signature”, options);

Any thoughts on what I am doing wrong?

Scopes are here: http://support.google.com/a/bin/answer.py?hl=en&answer=162105

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:33:48+00:00Added an answer on June 4, 2026 at 7:33 pm

    Hope this will help you. This is an working example which will get the user’s HTML signature or Update HTML signature

    /*
    ----------------------------------------------------------------------------------
    This function will update the HTML signature of a user.
    Input will be jason data
    To disable signature, pass an empty string as signature value
    sample parameter
    ob = {user='hps', signature='<b>Regards</b><br>Waqar'}
    
    To disable signature
    ob = {user='hps', signature=''}
    ----------------------------------------------------------------------------------
    */
    function updateSignature(ob) {
      //ob = {};
      //ob.user = "hps";
      //ob.signature = "<b>Regards</b><br>Waqar";
    
      var base = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/';
      var xmlRaw = '<?xml version="1.0" encoding="utf-8"?>'+
          '<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:apps="http://schemas.google.com/apps/2006">'+
          '<apps:property name="signature" value="'+htmlEncode(ob.signature)+'" />'+
          '</atom:entry>';
      var fetchArgs = googleOAuth_('emailSetting',base);
      fetchArgs.method = 'PUT';
      fetchArgs.payload = xmlRaw;
      fetchArgs.contentType = 'application/atom+xml';
      var domain = UserManager.getDomain();
      var url = base+domain+'/'+ob.user+'/signature';
      var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
      var status = urlFetch.getResponseCode();
      return status;
    }
    
    
    //-----------------------------------------------------------------------------------------------------------
    //This function will retreive Signature settings as json.
    /*Sample returned object
    {user=hps, signature=<b>Regards</b><br>Waqar}
    */
    //-----------------------------------------------------------------------------------------------------------
    function retrieveSignature(user) {
      var user = 'hps';
      var base = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/';
      var fetchArgs = googleOAuth_('emailSetting',base);
      fetchArgs.method = 'GET';
      var domain = UserManager.getDomain();
      var url = base+domain+'/'+user+'/signature?alt=json';
      var urlFetch = UrlFetchApp.fetch(url, fetchArgs);
      var jsonString = urlFetch.getContentText();
      var jsonArray = Utilities.jsonParse(jsonString).entry.apps$property;
      var ob = {};
      ob.user = user;
      for(var i in jsonArray){
        ob[jsonArray[i].name] = jsonArray[i].value;
      }
      return ob;
    }
    //Google oAuthConfig.. 
    function googleOAuth_(name,scope) {
      var oAuthConfig = UrlFetchApp.addOAuthService(name);
      oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
      oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
      oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
      oAuthConfig.setConsumerKey("anonymous");
      oAuthConfig.setConsumerSecret("anonymous");
      return {oAuthServiceName:name, oAuthUseToken:"always"};
    }
    
    
    //This function will escape '<' and '>' characters from a HTML string
    function htmlEncode(str){
      str = str.replace(/</g,'&lt;');
      return str.replace(/>/g,'&gt;')
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use Ruby Net::SMTP to send email. The routine send_message( msgstr,
Normally you would use something like attr_accessible :name, :email to allow for mass assignment
I have like 50 different php files which all use the mail function. After
I would like to send this email. I have seen configuration but not sure
We would like to use Selenium to test email content generated from our website.
I would like to use an xml file to create a html email. I
I would like to use OpenId on my site to allow user registration using
i would like use a variable session ($_session) but it doesn't work in Drupal
I would like to use the Eigen matrix library as the linear algebra engine
I would like to use DocumentFragment and querySelector to make and modify DocumentFragments. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.