0
votes

MailApp.sendEmail(emailAddress, subject, message);

to send out emails. We have this working on two domains, but on one it's not working. Emails bounce back, and the bounce back screen looks the same, regardless of the recipient, a traffic light with a red light on

Message blocked Your message to xyz@gmail.com has been blocked. See technical details below for more information. LEARN MORE

I suspect it's blocked by google. It may have to do with our account status. Manually sent emails go out fine. But emails sent via script do not, they do appear in the sent box, but then bounce back almost instantly.

Does anybody know how to fix this? We have already allowed less secure apps in the g suite security settings but this did not remedy the problem. The g suite access is part of a squarespace deal, so not directly bought from google. The account is around 2 months old now.

Thank you.

function sendEmails2() { 
  var EMAIL_SENT = "EMAIL_SENT"; 
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Press'); 
  var startRow = 2; 
  var numRows = 1; 
  var dataRange = sheet.getRange(startRow, 1, numRows, 100); 
  var data = dataRange.getValues(); 
  for (var i = 0; i < data.length; ++i) { 
    var row = data[i]; 
    var emailAddress = row[11]; 
    var have_email = row[12]; 
    var sendornot = row[16]; 
    var emailSent = row[17]; 
    if (emailSent != EMAIL_SENT && have_email == 1 && sendornot == 1) { 
      var subject = "Story Pitch"; 
      MailApp.sendEmail(emailAddress, subject, message, {'name':'Lisai'}); 
      sheet.getRange(startRow + i, 18).setValue(EMAIL_SENT); 
      SpreadsheetApp.flush(); 
    } 
  } 
}
1
The way we can be the most helpful is for you to give us some code and tell us what the problem is. We take the code and try to verify that we see the same problem and then we try to fix it. If we don't have code nor access to your environment we can only guess at what the problem might be. Once in while we might leave a message like this but most of the time we just move on to another question. - Cooper
function sendEmails2() { var EMAIL_SENT = "EMAIL_SENT"; var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Press'); var startRow = 2; // First row of data to process var numRows = 1; // Number of rows to process // Fetch the range of cells var dataRange = sheet.getRange(startRow, 1, numRows, 100) // 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[11]; // test set for var message = row[18]; // - Lisa Vianti
var have_email = row[12]; var sendornot = row[16]; var emailSent = row[17]; if (emailSent != EMAIL_SENT && have_email == 1 && sendornot == 1) { // Prevents sending duplicates var subject = "Story Pitch"; MailApp.sendEmail(emailAddress, subject, message, {'name':'Lisai'}); sheet.getRange(startRow + i, 18).setValue(EMAIL_SENT); // Make sure the cell is updated right away in case the script is interrupted SpreadsheetApp.flush(); } } } - Lisa Vianti
Welcome to StackOverFlow please take this opportunity to take the tour and learn how to How to Ask, format code and minimal reproducible example. - Cooper

1 Answers

1
votes

I just made a few minor changes but I think it looks okay to me.

function sendEmails2() { 
  var EMAIL_SENT = "EMAIL_SENT"; 
  var ss=SpreadsheetApp.getActive();
  var sheet=ss.getSheetByName('Press'); 
  var startRow=2; 
  var dataRange=sheet.getRange(startRow, 1, sh.getLastRow()-startrow + 1, sh.getLastColumn()); 
  var data=dataRange.getValues(); 
  for (var i=0;i<data.length;++i) { 
    var row=data[i]; 
    var emailAddress=row[11]; 
    var have_email=row[12]; 
    var sendornot=row[16]; 
    var emailSent=row[17]; 
    if (emailSent!=EMAIL_SENT && have_email==1 && sendornot==1) { 
      var subject= "Story Pitch"; 
      if(MailApp.getRemainingDailyQuota()<1) SpreadsheetApp.getUi().alert("Exceeded Daily Quota");
      MailApp.sendEmail(emailAddress, subject, message, {'name':'Lisai'}); 
      sheet.getRange(startRow + i, 18).setValue(EMAIL_SENT); 
      SpreadsheetApp.flush(); 
    } 
  } 
}