Bulk Email Sending System

Bulk Email Sending System is designed to simplify and streamline the process of sending personalized emails directly from your Google Sheets. This powerful tool leverages Google Apps Script, allowing you to send bulk emails without the need to manually enter your Gmail credentials, ensuring a seamless and secure experience.

Key Features:

Personalized Emails: Customize each email with recipient-specific details like Names & IDs directly from your Google Sheet.
Easy-to-Use Interface: With a simple custom menu in Google Sheets, you can send personalized emails with just a few clicks.
Subject Customization: The system prompts you to enter the email draft subject each time, ensuring that your messages are always relevant.
Batch Processing: Emails are sent in batches of 100 to comply with Gmail’s sending limits, ensuring smooth and uninterrupted email dispatch.
Detailed Logging: Track the exact date & time each email is sent, along with the status of each email, directly in your Google Sheet.

How It Works:

Prepare Your Data: List your recipients, along with their Names & IDs, in a Google Sheet.
Customize Your Draft: Write your email template in Gmail, using placeholders like {name} & {id} for personalization.
Send Emails: Use the custom menu in your Google Sheet to send emails. The system will replace placeholders with actual data and log the sending details.
Monitor and Track: Check the status of sent Emails, including the date, time, & any errors, all within your Google Sheet.

				
					function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Custom Menu')
    .addItem('Send Personalized Emails', 'sendPersonalizedEmailsFromDraft')
    .addToUi();
}

function sendPersonalizedEmailsFromDraft() {
  var ui = SpreadsheetApp.getUi();
  var response = ui.prompt('Send Personalized Emails', 'Please enter the email draft subject:', ui.ButtonSet.OK_CANCEL);
  
  if (response.getSelectedButton() == ui.Button.OK) {
    var draftSubject = response.getResponseText();
    
    if (draftSubject.trim() === "") {
      ui.alert('Draft subject cannot be empty. Please try again.');
      return;
    }
    
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    var data = sheet.getDataRange().getValues();
    
    // Get the draft email
    var drafts = GmailApp.getDrafts();
    var draft = null;
    for (var i = 0; i < drafts.length; i++) {
      if (drafts[i].getMessage().getSubject() === draftSubject) {
        draft = drafts[i];
        break;
      }
    }
    
    if (!draft) {
      ui.alert('Draft email not found. Please check the subject and try again.');
      return;
    }
    
    var draftMessage = draft.getMessage();
    var draftBody = draftMessage.getBody();
    var subject = draftMessage.getSubject();
    
    var dailyLimit = 1000;
    var batchLimit = 100; // Batch limit of 100 emails
    var sentEmails = 0;
    
    for (var i = 1; i < data.length; i++) {
      if (sentEmails >= dailyLimit) {
        Logger.log('Daily limit reached. Emails sent: ' + sentEmails);
        ui.alert('Daily limit reached. Emails sent: ' + sentEmails);
        return;
      }
      
      var emailAddress = data[i][0];  // First column
      var name = data[i][1];          // Second column
      var id = data[i][2];            // Third column
      var sendTimeCell = sheet.getRange(i + 1, 4); // Send Date & Time column
      var statusCell = sheet.getRange(i + 1, 5);   // Status column
      
      // Replace placeholders with actual values
      var personalizedBody = draftBody.replace("{name}", name).replace("{id}", id);
      
      try {
        GmailApp.sendEmail(emailAddress, subject, "", {
          htmlBody: personalizedBody
        });
        var currentTime = new Date();
        sendTimeCell.setValue(Utilities.formatDate(currentTime, Session.getScriptTimeZone(), "yyyy-MM-dd HH:mm:ss"));
        statusCell.setValue("Sent");
        sentEmails++;
        
        // If batch limit is reached, pause for a moment
        if (sentEmails % batchLimit === 0) {
          Utilities.sleep(5000); // Sleep for 5 seconds to avoid hitting rate limits
        }
      } catch (e) {
        statusCell.setValue("Failed: " + e.message);
      }
    }
    
    ui.alert('Emails sent to ' + sentEmails + ' recipients.');
  } else {
    ui.alert('Email sending cancelled.');
  }
}


				
			

How to Send Emails Using the Bulk Email Sending System

Prepare Your Google Sheet
– Open Google Sheets and create a new sheet.
– In the sheet, create the following columns:
Email Address: List the email addresses of your recipients.
Name: List the names of each recipient.
ID: Add any additional data you’d like to personalize (e.g., student ID, member number, etc.).

Example:
|  Email Address        |  Name      |  ID     |  Send Time          |  Status  |
———————————————————
|  info@icditc.club     | Aziz            | 552 |  1/12/2025 1:40:02  |  Sent     |  
|  info@icditc.club     | Arafat       | 456 |  1/12/2025 1:40:02  |  Sent     |

Write Your Email Draft in Gmail
– Open Gmail and compose a new email.
– Write the content of the email that will be sent to your recipients.
– Use placeholders (e.g., {name} and {id}) for personalizing the email. For example:

Subject: Important Notice for ICDITC

Hi {name},

Your ID is {id}. Please take note of this important information.

Set Up Google Apps Script
– Open the Google Sheet containing your recipient data.
– Go to ExtensionsApps Script.
– Copy and paste the provided script into the Apps Script editor (this will automate email sending).
– Save the script and close the editor.

Custom Menu to Send Emails
– After setting up the Apps Script, a custom menu will appear in your Google Sheet (e.g., “Email Sender”).
– Click on the custom menu and select the Send Emails option.

Enter the Email Draft Subject
– A popup will appear asking for the subject of the email. Type in the subject you want for this batch of emails (e.g., “Important Update”).
– Click OK to confirm.

Send the Emails
– Once you confirm the subject, the system will begin sending emails in batches of 100.
– The system will automatically personalize each email using the data from your Google Sheet (e.g., replacing {name} with each recipient’s name).

Track Sent Emails
– After the emails are sent, the system will log the following details in your Google Sheet:
– The date and time each email was sent.
– The status (whether the email was sent successfully or not).
– The number of emails sent in a day and in one batch.

Important Notes:
– Sending Limits: Gmail has a daily sending limit. The system is set to send emails in batches of 100 to ensure you don’t exceed this limit.
– Tracking: You can monitor how many emails have been sent in a day and keep track of each batch sent.
– Personalization: Make sure the placeholders in your Gmail draft (e.g., {name} and {id}) match the column headers in your Google Sheet.

Copyright © Md Abdul Aziz.
Contact: mdabdulazizarafat@gmail.com