function setAutoReply(leaverEmail, managerEmail) {
// resets all oauth to start fresh
reset();
// In our example the leaver is the user email so we set the USER_EMAIL to the leaver's email in the script properties
PropertiesService.getScriptProperties().setProperty('USER_EMAIL', leaverEmail);
// We go through the OAuth workflow to receive a token which will be saved in the script properties as
// oauth2.[SERVICE_NAME_YOU_SPECIFIED]:[USER_EMAIL] <-- that will be the email you will be impersonating with domain wide delegation
let service = getService_();
let responseBody = `
<p>
Thank you for your email. I am no longer at <strong>EXAMPLE COMPANY</strong>.
</p>
<br>
Please contact ${managerEmail} for assistance.
<br>
Thank you
`;
let responseSubject = 'No Longer at EXAMPLE COMPANY:';
const responseDateStart = Date.now();
let autoReplySettings = {
"enableAutoReply": true,
"responseSubject": responseSubject,
"responseBodyHtml": responseBody,
"restrictToContacts": true,
"restrictToDomain": true,
};
let options = {
"method": "PUT",
"headers": {
"Authorization": `Bearer ${service.getAccessToken()}`,
},
"contentType": 'application/json',
"payload": JSON.stringify(autoReplySettings),
}
let setAutoReplyResult = UrlFetchApp.fetch(fullURL, options);
Logger.log(setAutoReplyResult);
return true;
}