May 26, 2019

Use Google script to send different email to different people at Once Easily

Google has been constantly developing and taking it’s platform in whole new level. In the same way it has made us easy for sending message through it’s email service- Gmail.

You have a party and you have many friends who promised to help you to organizing the party. You want to message them now saying what their job is. The one thing you can do is open you email account and write email to all of them one by one which can take lot of time. But this tutorial will help you send different message to different people at once with the help of Google spreadsheet.

The First thing you have to do is go to Google Document and log in to your Google account. After you are logged in you can see a Create at the upper left corner of your Screen. Click on it and choose SpreadSheet.

Create two Column where column A contain a Email address and column B contains Message. You can name column A as “Email address” and column B as “Message”.


google spreadsheet


Fill the Email address column with the email address of your friends or even write down your own email address to test if you receive the message or not. Message column with the message that you want to send to your friends. When you are finished writing the email address and the message than on the Menu click on Tools and choose Script editor…

Paste the following code on the script editor.

[code lang=”js”]// This constant is written in column C for rows for which an email
// has been sent successfully.

function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 3; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 3)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = row[1]; // Second column
var emailSent = row[2]; // Third column
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var subject = "Sending emails from a Spreadsheet";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 4).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted


You can tweak the code if you want. If you have more than 3 friends whom you want to send the message unlike me than you can change the code.

[code lang=”js”]var numRows = 3; // Number of rows to process[/code]

On this line just give the number of email address that you have written on the spreadsheet. Save it and rename the app as you like. When you are finished, click on Run symbol or click on Run on the Menu and click on SendEmail2.  After that you will be asked to authorize the app. Go ahead and click on Continue and give permission.

After giving permission go back and again click on Run. That is it, it is really simple. If you go to your spreadsheet tab you can see the third column has been added and you are notified that the email has been sent. If you go to your email address and check the email you can probably see that the email address has arrived.

sent email google script

Using this app you send different email to different people at once. You can also make a app that you can send a document to yourself or any friends of yours easily.

If you got any problem than just ask us. We are always ready to help you. Give us your feedback if you got any.

About Bhattarai Diwas (thenepaltech) 213 Articles
I'm an Engineer and have Bachelor's Degree in Electrical and information technology. Right now I am working as a software developer in Germany. All in all I love programming and I am a tech geek.