Scroll to Top
💻
Free Code
Users get ready-to-use code at no cost.
📋
Easy Copy
Copy and use the code instantly.
Quick Learning
Understand concepts fast and clearly.
📝
Step-by-Step
Follow simple instructions to implement.
📅 August 28, 2025 💻 Tutorial ⭐ Beginner Friendly

Monitor Website Downtime

Author Avatar

Ashish Dwivedi

Editorial Team • Tech Writer

About This Tutorial

  1. Step 1: Click on the Copy button to copy the code snippet.
  2. Step 2: Paste the copied code into your project’s script editor.

Apps Scripts Blog

Read Blog

📂 javascript
⚡ script1.js
⚡ script1.js
ction checkWebsitesStatus() { 
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 
  const headers = ["Website URL", "Status", "HTTP Code", "Reason", "Checked At"]; 
  const urls = [ 
    'https://www.mailsextract.com/', 
    'https://www.outrightsystems.org/', 
    'https://store.outrightcrm.com/', 
  ]; 
  const recipient = 'monitoring@example.com'; 
  if (sheet.getLastRow() === 0) { 
    sheet.getRange(1, 1, 1, headers.length).setValues([headers]); 
  } 
  let messageBody = ''; 
  urls.forEach(url => { 
    let status = 'UP'; 
    let code = ''; 
    let reason = ''; 
    let message = ''; 
    try { 
      const response = UrlFetchApp.fetch(url, { muteHttpExceptions: true }); 
      code = response.getResponseCode(); 
      if (code >= 400) { 
        status = 'DOWN'; 
        reason = getStatusExplanation(code); 
        message = `❌ Website is DOWN: ${url}\nStatus Code: ${code}\nReason: ${reason}`; 
      } 
    } catch (error) { 
      status = 'DOWN'; 
      reason = error.message; 
      message = `❌ Website is DOWN: ${url}\nError: ${reason}`; 
    } 
    if (status === 'DOWN') { 
      const timestamp = new Date(); 
      sheet.appendRow([url, status, code || '-', reason, timestamp]); 
      messageBody += `${message}\nChecked At: ${timestamp.toLocaleString()}\n\n`; 
    } 
  }); 
  if (messageBody) { 
    MailApp.sendEmail(recipient, 'Website Downtime Alert', messageBody); 
  } 
} 
function getStatusExplanation(code) { 
  const explanations = { 
    400: 'Bad Request – The server could not understand the request.', 
    401: 'Unauthorized – Authentication is required.', 
    403: 'Forbidden – You do not have permission.', 
    404: 'Not Found – The page is missing.', 
    500: 'Internal Server Error – Server issues.', 
  }; 
  return explanations[code] || 'Unknown error'; 
}