Search code examples
google-apps-scriptgmailgmail-apiservice-accountsgoogle-workspace

Modify the signature for all users in my domain


Currently my code only modifies my signature, because when I put the email of the other person in my domain, the error: Not Found (line 9, file "Code") appears.

My current code:

function myFunction() {
  var newSignature = Gmail.newSendAs();
  newSignature.signature = "signature";

  var listEmails = [
    "[email protected]"]

  var updateSignature = Gmail.Users.Settings.SendAs.update(newSignature, "me", listEmails)
}

I am developing using APPS SCRIPT.

Any suggestions for me to be able to change the signature of someone else in my domain?


Solution

  • To change other people Gmail settings in your domain you'll need to be a domain Admin, then create a service account with domain-wide authority, then whitelist it in the Admin Console. Then use said service account and authentication token generated to authenticate your requests to the Gmail API.

    This built-in Apps Script Gmail integration was not made for that use-case. The intended usage is to setup your own settings, or individual users that explicitly authorize your application to run on their behalf. This sendAs is there because one might have multiple Gmail signatures, depending on their selected send-as/from alias.

    Note that simply authorizing an script with your GSuite admin account won't allow to the script to perform domain-wide operations. That'd be too dangerous, therefore the somewhat convoluted service-account setup is required.

    Link to the relevant documentation