Back to the introduction guide
Complete scripts ready to copy

Google Apps Script Automation Examples

Copy and paste these professional scripts, configured step-by-step, to automate Google Sheets, Gmail, Drive, and Agenda instantly.

💡 How to install these scripts in your document?

1

In your Google Sheet, click Extensions > Apps Script.

2

Delete any existing code and paste one of our examples below.

3

Customize the parameters (such as folder IDs), save, and click Run.

Select an automation to install:

Automated Unpaid Invoice Email Reminders

Sheets + Gmail

Loops through your billing rows in Google Sheets, identifies clients with "Unpaid" status, sends a professional, customized HTML email reminder, and writes the sent date in the sheet to prevent duplicates.

Document configuration:

Recommended columns structure:

  • Column A (index 0): Client name (e.g. ABC Company)
  • Column B (index 1): Client email address
  • Column C (index 2): Invoice amount (e.g. 1500)
  • Column D (index 3): Due date (Date format)
  • Column E (index 4): Invoice status (type Non Payé or Unpaid to trigger the reminder)
  • Column F (index 5): Reminder status (leave blank, the script will write Sent on DD/MM/YYYY HH:MM)

Setup instructions:

  1. Set up your Google Sheet with the column structure above.
  2. Add a few test rows using your own email address in column B.
  3. Paste the code on the right into the Google Apps Script editor.
  4. Click Run. On the first launch, authorize the required security permissions (see auth steps below if needed).
relance_impayes.gs
function relancerFacturesImpayees() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const dataRange = sheet.getDataRange();
  const values = dataRange.getValues();
  
  // Index des colonnes (0 = Colonne A, 1 = B, etc.)
  const COL_NOM = 0;
  const COL_EMAIL = 1;
  const COL_MONTANT = 2;
  const COL_ECHEANCE = 3;
  const COL_STATUT = 4;
  const COL_RAPPEL = 5;
  
  let rappelsEnvoyes = 0;
  
  // Parcourir à partir de la ligne 2 (index 1) pour ignorer les en-têtes
  for (let i = 1; i < values.length; i++) {
    const row = values[i];
    const nom = row[COL_NOM];
    const email = row[COL_EMAIL];
    const montant = row[COL_MONTANT];
    const echeance = row[COL_ECHEANCE];
    const statut = row[COL_STATUT];
    const rappelEnvoye = row[COL_RAPPEL];
    
    // Vérifier si la facture n'est pas payée et qu'aucun rappel n'a été envoyé
    if ((statut === "Non Payé" || statut === "Unpaid") && !rappelEnvoye) {
      if (email && email.indexOf("@") !== -1) {
        
        // Formater la date d'échéance
        const dateFormatee = echeance instanceof Date ? Utilities.formatDate(echeance, Session.getScriptTimeZone(), "dd/MM/yyyy") : echeance;
        
        // Template d'e-mail HTML personnalisé
        const sujet = "Rappel de paiement : Facture en attente - " + nom;
        const corpsHtml = `
          

Rappel de paiement

Bonjour ${nom},

Sauf erreur de notre part, le règlement de votre facture d'un montant de ${montant} €, qui était attendu pour le ${dateFormatee}, ne nous est pas parvenu.

Nous vous demandons de bien vouloir régulariser cette situation dans les plus brefs délais.


Ceci est un message automatique envoyé depuis notre gestionnaire de facturation.

`; try { // Envoyer l'email MailApp.sendEmail({ to: email, subject: sujet, htmlBody: corpsHtml }); // Mettre à jour le statut du rappel dans la feuille de calcul const dateAujourdhui = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd/MM/yyyy HH:mm"); sheet.getRange(i + 1, COL_RAPPEL + 1).setValue("Envoyé le " + dateAujourdhui); rappelsEnvoyes++; Logger.log("Rappel envoyé à " + nom + " (" + email + ")"); } catch (erreur) { Logger.log("Erreur lors de l'envoi de l'e-mail à " + email + " : " + erreur.message); } } } } Browser.msgBox("Traitement terminé : " + rappelsEnvoyes + " rappel(s) envoyé(s)."); }

🛡️ Google Security Alert: Don't panic!

When you run a script for the very first time, Google displays a large red warning panel stating that the application isn't verified. This is a standard protection for all privately created scripts. Here is how to pass it safely:

1. Advanced Settings

On the warning panel, click on the Advanced link at the bottom left.

2. Force Access

Then, click on the small link Go to [Your Project Name] (unsafe). Don't worry, the script remains private and runs only inside your space.

3. Allow Access

A window summarizes what the script will access (read Sheets, send emails). Click Allow. Your data remains secure and private inside your Google account.