View Full Version : Gmail Mail Merge Script

05-23-2012, 05:41 PM
Hi guys,

im editing the mail merge script by labnol (sorry if you have not seen it) anyway i'm pretty much done with it now however just having one issue.

here goes, right so i've pulled my information from google contacts below fine, i added the "getNotes" which works fine and also enters the information into column C of my spreadsheet. Fine

if (myGroup) {
var myContacts = myGroup.getContacts();
for (i=0; i < myContacts.length; i++) {
mySheet.getRange(i+2, 1, 1, 1).setValue(myContacts[i].getFullName());
mySheet.getRange(i+2, 2, 1, 1).setValue(myContacts[i].getPrimaryEmail());
mySheet.getRange(i+2, 3, 1, 1).setValue(myContacts[i].getNotes());

my problem is getting the information back from the this column in the sheet and changing row, per each email.

this is how labnol does it for "person" (at the start of this code) i pretty much need to do the same but think i have tried everyway but the right way

var myContact = mySheet.getDataRange().getValues();

for (i=1; i < myContact.length; i++) {
var person = myContact[i];
if (person[0] != "" && person[1] != "" && person[2] != "OK") {
var emailMsg = emailSalutation + " " + person[0] + ", <br /><br />" + emailBody + trade[2] + "<br /><br />";
var advancedArgs = {htmlBody:emailMsg, name:emailYourName, replyTo:replyToAddr};

if (file)
advancedArgs["attachments"] = attachmentID;

if (emailBCC == "YES")
advancedArgs["bcc"] = emailYourAddr;

GmailApp.sendEmail(person[1], emailSubject, emailMsg, advancedArgs);

any help would be awesome!

Darkinsomn1a (Ps sorry if i posted this in the wrong place)