Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

69
Visualizações
Why is this LockService not stopping it from invoking GmailApp service?

I'm trying to get the lock for 5 seconds and I try running it concurrently and it throws the know error: Exception: Service invoked too many times for one day: email.

This is how I'm trying to get it:

function sendEmail() {

  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getActiveSheet();
  if (sheet.getName() != 'Todays Tests V2') {
    return;
  }

  const testSheet = ss.getSheetByName("Todays Tests V2");
  const row = sheet.getActiveCell().getRow();
  const col = sheet.getActiveCell().getColumn();
  const sendResults = testSheet.getRange(row, 15, 1, 1).getValue();

  if (ss.getActiveSheet().getSheetName() == testSheet.getSheetName() &&
    row > 5 &&
    col == 15 &&
    sendResults == true) {

    const lock = LockService.getScriptLock();
    try {
      lock.tryLock(5000); // wait 05 seconds for others' use of the code section and lock to stop and then proceed
    } catch (e) {
      Logger.log('Could not obtain lock after 05 seconds.');
      return HtmlService.createHtmlOutput("<b> Server Busy. Please try after some time <p>");
    }
    const email = testSheet.getRange(row, 5).getValue();
    const name = testSheet.getRange(row, 3).getValue() + ' ' + testSheet.getRange(row, 4).getValue();
    const testNo = testSheet.getRange(row, 2).getValue();

    GmailApp.sendEmail(email, "subject", name + " XXXXXX.", { name: 'Custom Name' });
    lock.releaseLock();
  }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try using a different account or wait 1 day.

The above because the error message means that the account that you are currently using have exceeded the referred quota.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can review the limits here: https://developers.google.com/apps-script/guides/services/quotas

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda