Re: Email notification does not work

45 views
Skip to first unread message
Message has been deleted

Dominique Rouillard

unread,
Jun 25, 2024, 4:48:49 AM (8 days ago) Jun 25
to Google Ads Scripts Forum
Hello,

Voici le script ajusté 

var CONFIG = {
  alertLimit: 500, // Limite d'alerte fixée à 500
  email: ['vasi...@gmail.com'],
  names: ['Nick', 'Nick2']
};

function main() {
  var accountName = AdWordsApp.currentAccount().getName();
  var customerId = AdWordsApp.currentAccount().getCustomerId();
 
  // Obtenir le solde actuel du compte
  var balance = getAccountBalance();

  var messageHeader = CONFIG.names.join(", ") + ' / Заканчивается бюджет на аккаунте: ' + accountName;
  var messageBody = 'Привет, ' + CONFIG.names.join(", ") + '!\n\n' +
      'Аккаунт ' + accountName + ' (' + customerId + '). Текущий остаток = ' + balance.toFixed(2) +
      ' USD.\n\n' +
      'В аккаунте заканчиваются средства. Необходимо предупредить PM.\n\n' +
      'С наилучшими пожеланиями,\nВаша система уведомлений';

  if (balance < CONFIG.alertLimit) {
    MailApp.sendEmail(CONFIG.email, messageHeader, messageBody);
    Logger.log('Alerte envoyée pour le compte: ' + accountName + ' avec un solde de: ' + balance.toFixed(2) + ' USD.');
  } else {
    Logger.log('Pas d\'alerte. Solde actuel: ' + balance.toFixed(2) + ' USD.');
  }
}

function getAccountBalance() {
  var stats = AdWordsApp.currentAccount().getStatsFor("ALL_TIME");
  var totalCost = stats.getCost();
  var budgetOrders = AdWordsApp.budgetOrders().get();
  var totalBudget = 0;

  while (budgetOrders.hasNext()) {
    var budgetOrder = budgetOrders.next();
    totalBudget += budgetOrder.getSpendingLimit();
  }

  var balance = totalBudget - totalCost;
  return balance;
}

Le lundi 24 juin 2024 à 10:50:40 UTC+2, Василий Александрович a écrit :
Hello, please help me with a problem.
The script for email notification of the current account balance does not work.
I need an email notification when the current account balance (not in MCC) is less than 500. Can you please see what is wrong with the code?
Google Ads account     384-537-7276
Name of the affected script    Notification

Script Code:
var CONFIG = {
  days: 7,
  alertLimit: 3000,
  email: ['vasi...@gmail.com'],
  names: ['Nick', 'Nick2'],
  }
function main() {
  var accountName = AdWordsApp.currentAccount().getName();
  var budgetNow = AdWordsApp.budgetOrders().get();
  var messageHeader = CONFIG.names + ' / Заканчивается бюджет на аккаунте: ' + accountName;
  var messageBody = 'Аккаунт ' + accountName + ' . Текущий остаток = ' + budgetNow +
      'В аккаунте заканчиваются средства. Необходимо предупредить PM.';
  if (budgetNow < CONFIG.alertLimit) {
    MailApp.sendEmail(CONFIG.email, messageHeader, messageBody);
      Logger.log([accountName, budgetNow]);
    }
  }

Google Ads Scripts Forum Advisor

unread,
Jun 25, 2024, 7:23:24 AM (8 days ago) Jun 25
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

Please be informed that this product officially offers support only in English. It would be best to reply in English if you can. If not, we will try to use Google Translate to support you as best as we can.

I would recommend that you replace the code “email: ['vasi...@gmail.com'],” with “email: 'vasi...@gmail.com',” to resolve the issue.

Kindly note that I have removed your first response from the forum as it contains the PII information.

I hope this helps! Kindly get back to us if you still face any issues. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02tJSfH:ref" (ADR-00243723)

Thanks,
 
Google Logo Google Ads Scripts Team


Василий Александрович

unread,
Jun 28, 2024, 10:00:45 AM (5 days ago) Jun 28
to Google Ads Scripts Forum
Dominique Rouillard and
Google Ads Scripts Forum Advisor
Thanks a lot for your help

вторник, 25 июня 2024 г. в 14:23:24 UTC+3, Google Ads Scripts Forum Advisor:

Rindou Haitani

unread,
Jun 29, 2024, 9:39:08 PM (3 days ago) Jun 29
to Dominique Rouillard via Google Ads Scripts Forum
thanks

Vào Th 3, 25 thg 6, 2024 vào lúc 15:48 Dominique Rouillard via Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/e2dea92c-ae24-4f64-ae82-8401d4baf02dn%40googlegroups.com.

Antoine Edmonds

unread,
Jul 1, 2024, 4:58:20 AM (2 days ago) Jul 1
to Google Ads Scripts Forum
PostAnalytics_DeontawnetteEdmonds_7208399361288921088.xlsx

Google Ads Scripts Forum Advisor

unread,
Jul 1, 2024, 5:44:58 AM (2 days ago) Jul 1
to adwords...@googlegroups.com
Hi,

After verifying the provided code snippet, I could see that you're passing the parameters (number[],String,String) which does not match the method signature for MailApp.sendEmail. I would suggest you check out these examples of MailApp and modify your code accordingly. 

Let us know if you face any issues. 
Reply all
Reply to author
Forward
0 new messages