Just paste this code in script editor(Tools > Script editor)

Note:-Before we can create a Google Apps Script to send an email from spreadsheet(GOOGLE SPREADSHEET), you will also need a Gmail-Id, which Google Apps Script will use to send out your alert emails.

we willl also need to create a new spreadsheet that contains an email address.

Just add a name column and an email-id column, and then fill them out with the person you want to receive the alert email.This code will send email to single email id at a time(based on cell value(Email id cell)),when we need to send email to particular email id then we have to select that single row of spreadsheet and then click on ‘send email’ custom menu.

//Creating custom menu ‘Send Mail’in Google spreadsheet.

function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu(“Send Mail”)
.addItem(‘Send Mail To Concerned’, ‘SendMail’)
.addToUi();
}

//

//Email code

function onInstall(e) {
onOpen(e);
}
var EMAIL_SENT = ‘EMAIL SENT’;
function SendMail() {
var ss = SpreadsheetApp.getActive();

var TaskNumberSheet = ss.getSheetByName(‘Sheet1’);
var TaskNoRow = TaskNumberSheet.getActiveCell().getRow();
var TaskNoCol = 1;
var TaskNoCol1 = 4;
var TaskNo = TaskNumberSheet.getRange(TaskNoRow, TaskNoCol).getValue();
var message = TaskNumberSheet.getRange(TaskNoRow, TaskNoCol1).getValue();
var subject = ‘Content Available’;
MailApp.sendEmail(TaskNo, subject, message);
SpreadsheetApp.flush();
}

//

After all this when we send email for the first time then there will be authorization alert ,so we must Click on Review Permissions, and we will see another alert screen after this Just click on Advanced, and then click the Go to Send Email (unsafe) link..

One Reply to “How to send email from Google spreadsheet using Script.”

Leave a Reply

Your email address will not be published. Required fields are marked *