Script looks fine. You might want to check the email addresses you have in sheet1 to ensure they are formatted correctly.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/ad00534f-556a-4d00-8375-ccb973b4af78n%40googlegroups.com.
Do some debugging to see what value is in emailAddress.
Add this Logger.log statement as below:
function sendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Sheet1');
var sheet2=ss.getSheetByName('Sheet2');
var subject = sheet2.getRange(2,1).getValue();
var n=sheet1.getLastRow();
for (var i = 2; i < n+1; i++){
var emailAddress = sheet1.getRange(i,2).getValue();
var message = sheet2.getRange(2,2).getValue();
Logger.log(emailAddress);
MailApp.sendEmail(emailAddress,subject, message);
}
}
It should be a nice simple email address printed. If you get something else, then its picking up some garbage from somewhere it should not.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1101f140-53b6-4819-8d8d-110c408b476fn%40googlegroups.com.
I was looking at this email on my mobile and it was showing a line break after emailAddress in this line:
MailApp.sendEmail(emailAddress,subject, message);
There may be some hidden chararcters there. Delete the line and retype it.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/1101f140-53b6-4819-8d8d-110c408b476fn%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/P-ltuFXpw-Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/00dc01d97966%242f578430%248e068c90%24%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CALs7xtsaG%3DzW%2BVEDFyT3g-c-zpSMkxXf5o3svSFQDSxKNhrYMw%40mail.gmail.com.