简体   繁体   中英

Google script won't sent out the emails using Gmailapp.sendemail()

I try to use google script to send out some automation emails based on values from a google sheet. all the variables are not in HTML format for the email body or email subject. the execution is complete but no email received. here is the sample code:

   if(activitytype == "CTV" && datectvreceived == ""){
     if(firstattemp == "" && 5000 >firstattempdays > 1){

       var logic1message = l1content1 + plemail + l1content2 + ccemail +  l1content3 + pvcemail + l1content4 +protocolNum + l1content5 + protocolNum + '-'+ studytitle + l1content6 + reportperiod + l1content7;


           GmailApp.sendEmail(pvoemail,'First Attempt Reminder: ' +protocolNum ,logic1message);
       }// first logic 

    else if(firstattemp != "" && secondattemp == "" && 5000>secondattempdays > 7){

      var logic2message = l2content1 + plemail + l2content2 + ccemail+ l2content3 + pvcemail + l2content4 + protocolNum + l2content5 + protocolNum + '-' + studytitle + l2content6 + reportperiod + l2content7 + firstattemp + l2content8;
            GmailApp.sendEmail(pvoemail,'Second Attempt Reminder: '+ protocolNum,logic2message);

       } //second logic

    else if(secondattemp != "" && firstattemp != "" && thirdattemp == "" && 5000>thirdattempdays > 7){
      var logic3message = l3content1 + plemail + l3content2 + ccemail + l3content3 + pvcemail + l3content4 + protocolNum + l3content5 + protocolNum + '-' + studytitle + l3content6 + reportperiod + l3content7 + firstattemp + '&' + secondattemp + l3content8;

            GmailApp.sendEmail(pvoemail,'Third Attempt Reminder: ' + protocolNum,logic3message);

    } // third logic

    else if (thirdattemp != "" &&  secondattemp != "" && firstattemp != "" &&srtattemp == "" && 5000 >srtattempday > 7){
      var logicsrtmessage = lscontent1 + plemail + lscontent2 +ccemail + lscontent3 + pvcemail + lscontent4 + firstattemp + lscontent5 + secondattemp + lscontent6 + thirdattemp + lscontent7;

            GmailApp.sendEmail(pvoemail,'SRT Esaclation Reminder: '+ protocolNum,logicsrtmessage);

    } //srt logic

    sheet.getRange(startRow +i, 26).setValue(EMAIL_SENT); // a note for the protocols which email were sent
    SpreadsheetApp.flush();}
    else {sheet.getRange(startRow +i, 26).setValue(No_Email_Sent);
          SpreadsheetApp.flush();

please advice. thank you guys!!!!!

I believe you need to change all your if, else if(s)

if(firstattemp == "" && 5000 >firstattempdays > 1){

This is equivalent to

if( ( firstattemp == "" )  && ( ( 5000 >firstattempdays ) > 1) ) {

So ( 5000 >firstattempdays ) is either true or false

and ( true > 1 ) is false and ( false > 1 ) is also false

Change these to

if( ( firstattemp == "" ) && ( 5000 > firstattempdays ) && ( firstattempdays > 1) ) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM