Skip to content

How to Easily Automate Sending Emails Directly From Google Sheets

Get Started with Automating Emails Using Google Apps Script

Craving an easier way to manage and send bulk emails? This tutorial will guide you through automating emails using Google Apps Script. With this handy tool, you can utilize Google Sheets and Gmail to send personalized emails to a multitude of recipients. Whether it’s a newsletter, event invite, or company announcement, this automation process will make your life a lot easier. Let’s dive in!

Google Apps Script is a cloud-based scripting language for light-weight application development in the G Suite platform. It provides easy ways to automate tasks across Google products and third-party services.

Prepping Your Tools

Before we jump into the technical details, let’s make sure you have everything you need:

  • A Google Account (so you can use Google Sheets and Gmail)
  • Basic knowledge of JavaScript (Google Apps Script is based on JavaScript)

If you’re all set, let’s start crafting our automated email sender.

Step 1: Create Your Email List in Google Sheets

First, we need a list of recipients. We’ll use Google Sheets to manage this list.

1. Open Google Sheets.
2. Create a new blank sheet.
3. In the first row, label the columns as follows: 'First Name', 'Last Name', 'Email', and 'Message'. These headers will help us manage our data.

Populate the sheet with your recipients’ data. Make sure the emails are valid to prevent errors.

Step 2: Setting Up Google Apps Script

Next, we’ll create the script that will automate the email sending process.

1. Click on 'Extensions' in the menu bar of your Google Sheet, then select 'Apps Script'.
2. This will open a new tab with the Google Apps Script Editor.

Step 3: Crafting the Script

Now, let’s write the script. Don’t worry, we’ll walk through each part.

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = sheet.getLastRow()-1;   // Number of rows to process
  var dataRange = sheet.getRange(startRow, 1, numRows, 4);
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; i++) {
    var row = data[i];
    var firstName = row[0];  // First column
    var lastName = row[1];   // Second column
    var emailAddress = row[2];  // Third column
    var message = row[3]; // Fourth column
    var subject = 'Hello ' + firstName + ' ' + lastName;
    MailApp.sendEmail(emailAddress, subject, message);
  }
}

Here’s a breakdown of what the script does:

  1. SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); accesses the active sheet in our spreadsheet.
  2. We’re defining startRow as 2 since the first row is our header, not actual data.
  3. sheet.getLastRow()-1; gets the number of rows in the sheet, subtracting one to avoid the header row.
  4. sheet.getRange(startRow, 1, numRows, 4); gets the range of data from the sheet.
  5. We loop over the data with a for loop. For each row, we assign variables to each column’s value.
  6. MailApp.sendEmail(emailAddress, subject, message); sends the email to each recipient with their specific details.

Step 4: Run the Script

Time to put our script to the test

.

1. Click on the disk icon or select 'File > Save' to save your script. Name it 'SendEmails'.
2. To run the script, select the 'SendEmails' function in the dropdown menu, then click the play icon.

Upon running the script, Google will ask for permissions to send emails from your Gmail account. Grant the necessary permissions to proceed.

And there you have it! With a dash of Google magic, you’ve automated sending emails. Test and tweak your script as necessary for your unique needs. Now you can reach out to a list of recipients without manually crafting each email. Happy emailing!