1

I'm using a script from another thread on here to send out of office replies on my regular days off each week: Can I set Gmail "out of office" replies for every week recurring?

It sends plain text replies as follows:

var message = "This is my day off.";
// several lines later....
  threads[i].reply(message);

Can anyone tell me how to adapt this so that var message is injecting a HTML formatted reply?

1 Answer 1

3

One can include an HTML message in reply by using the reply(body, options) syntax, instead of the reply(body) syntax used above. Plain text body must still be provided for those clients who do not render HTML in messages.

The relevant parts are

var message = "This is my day off.";
var htmlMessage = "This is <strong>my day off</strong>.";
//  later 
  threads[i].reply(message, {htmlBody: htmlMessage});

The complete script becomes

function autoReply() {
  var interval = 5;          //  if the script runs every 5 minutes; change otherwise
  var daysOff = [4,5,6,0];   // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
  var message = "This is my day off.";
  var htmlMessage = "This is <strong>my day off</strong>.";
  var date = new Date();
  var day = date.getDay();
  if (daysOff.indexOf(day) > -1) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    for (var i = 0; i < threads.length; i++) {
      threads[i].reply(message, {htmlBody: htmlMessage});
    }
  }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.