I sucessfully created a script to generate signatures to users in g-suite domain using this topic as a guide. Now my problem is that this script only changes signatures "for new email use" but i need that "on reply/forward use" signatures to be update also using this script.
Is it possible?
This is the code i used as example and it is working to change signatures when composing new e-mails.
function setSignatureWithHTTPRequest(email, signature) {
var signatureSetSuccessfully = false;
var authorizationScope = ['https://www.googleapis.com/auth/gmail.settings.sharing'];
var service = getDomainWideDelegationService("Gmail: ", authorizationScope, email);
if (!service.hasAccess()) {
Logger.log("failed to authenticate as user " + email);
Logger.log(service.getLastError());
signatureSetSuccessfully = service.getLastError();
return signatureSetSuccessfully;
} else {
Logger.log("successfully authenticated as user " + email);
}
var username = email.split("@")[0];
var resource = { signature: signature };
var requestBody = {};
requestBody.headers = {"Authorization": "Bearer " + service.getAccessToken()};
requestBody.contentType = "application/json";
requestBody.method = "PUT";
requestBody.payload = JSON.stringify(resource);
requestBody.muteHttpExceptions = false;
var emailForUrl = encodeURIComponent(email);
var url = "https://www.googleapis.com/gmail/v1/users/me/settings/sendAs/" + emailForUrl;
try {
var setSignatureResponse = UrlFetchApp.fetch(url, requestBody);
signatureSetSuccessfully = true;
Logger.log("setSignatureResponse on successful attempt:" + setSignatureResponse);
} catch (e) {
Logger.log("Set signature with HTTP request failed: " + e);
}
return signatureSetSuccessfully;
}
Thanks in advance.
EDIT: Just to make clear what i need help with: In gmail's configuration (gmail -> sell all settings) web interface you can see that the field "signature" has two options to set signatures, "for new emails use" and "on reply/forward use". When i run my script it automatically changes only the first option (for new emails use), which means that whenever i compose emails it will send with the right signature i created from script, but it dosen't change the second one (on reply/forward use), which means that when i reply or forward e-mails it will not use the signature i created, unless i manually change it.
Can someone help me with that please? I'm still stuck with this.