All, I am looking for help from someone with more experience with this. I have a cobbled together email script that works great as is. I want to specify the from: address using an alias and it's my understanding that I need to use GmailApp vs MailApp to accomplish this. The trouble is, I can't figure out how to make my htmlBody work in the GmailApp version.
Here is my working MailApp code:
function SendPreReleaseAlertEmail(row) {
var sheet = SpreadsheetApp.getActive().getSheetByName('EmailSheet');
var subject = sheet.getRange("M3").getValues(); // Change the subject as needed.
var recipients = sheet.getRange("M2").getValue(); // Change the recipient as needed.
var message = "<HTML><BODY>" + "<P>"
for (var x=6;x<14;x++) { //Loop from * to * with a +1 increment
message = message + sheet.getRange("M" + x).getValues() + "<BR>" //Add row I(x) to the message
}
message = message + "</HTML></BODY>";
MailApp.sendEmail(recipients, subject, "", {htmlBody: message});
}
And this is my FAILED attempt at converting it to GmailApp with a From address:
function SendPreReleaseAlertEmail(row) {
var sheet = SpreadsheetApp.getActive().getSheetByName('EmailSheet');
var subject = sheet.getRange("M3").getValues(); // Change the subject as needed.
var recipients = sheet.getRange("M2").getValue(); // Change the recipient as needed.
var message = "<HTML><BODY>" + "<P>"
for (var x=6;x<14;x++) { //Loop from * to * with a +1 increment
message = message + sheet.getRange("M" + x).getValues() + "<BR>" //Add row I(x) to the message
}
message = message + "</HTML></BODY>";
GmailApp.sendEmail(recipients, subject, {htmlBody: message}, {from: "[email protected]"});
}
The above code does in fact email from the alias. But the htmlBody just has the words "[object Object]" in the body of the email.
It's Alive! Here is the final code that solved my problem:
GmailApp.sendEmail(recipients, subject, '', {htmlBody: message, from: "[email protected]"});