Google sheets script to send email

前端 未结 1 1387
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 15:18

link to the sheet

I just need the script (sendEmail02()) to collect data from the table of only the person whose mail is contained in column 2 and send him all

1条回答
  •  鱼传尺愫
    2021-01-26 15:57

    This function collects all of the messages for each recipient and sends each recipient one email with all messages in it. I modified the messages to make them simpler for debugging purposes so you will need to rewrite your messages.

    I also used a dialog to display message content rather than sending emails so you'll have to enable that and test it yourself.

    function sendEmail02() {
      var ss=SpreadsheetApp.getActive();
      var sh=ss.getSheetByName('Sheet1');
      if (sh.getName()=='Sheet1')  {
        var rg=sh.getRange(2,1,sh.getLastRow()-1,3);//What about column 4?
        var v=rg.getValues();
        var mObj={rA:[]};
        var html='';
        for (var i=0;iEmail:%s Text:%s',v[i][1],v[i][2]);
            if(mObj.hasOwnProperty(v[i][1])) {
              mObj[v[i][1]]+=message;
              mObj[v[i][1]+'rows'].push(i+2);
            } else {
              mObj[v[i][1]]=message;
              mObj.rA.push(v[i][1]);
              mObj[v[i][1]+'rows']=[];
              mObj[v[i][1]+'rows'].push(i+2);
            } 
          }
        }
        for(var i=0;iRecipient: %s
    Subject; %s
    Message:
    %s

    ',SendTo,Subject,mObj[mObj.rA[i]]) for(var j=0;j

    I tested it with you data and this is the dialog output after setting all the lines in column one to sent.

    Recipient: test01@gmail.com
    Subject; Hello
    Message:
    
    Email:test01@gmail.com Text:Data1
    Email:test01@gmail.com Text:Data2
    Email:test01@gmail.com Text:Data3
    Email:test01@gmail.com Text:Data6
    Email:test01@gmail.com Text:Data7
    
    Recipient: test02@gmail.com
    Subject; Hello
    Message:
    
    Email:test02@gmail.com Text:Data4
    
    Recipient: test03@gmail.com
    Subject; Hello
    Message:
    
    Email:test03@gmail.com Text:Data5
    Email:test03@gmail.com Text:Data8
    Email:test03@gmail.com Text:Data9
    

    0 讨论(0)
提交回复
热议问题