6

I've been frolicking around sending emails from Google Spreadsheet.

The sent email has two requirements to fill:

  • It needs to be send from my work-alias
  • It needs to be as HTML

I can do the former with:

GmailApp.sendEmail(to,subject,body,{from:alias,replayTo:alias})

Given a proper definition of 'alias', that works very well.

I can do the latter with:

MailApp.sendEmail(to,subject,"",{htmlBody:body})

But, perhaps you guessed it:

  • GmailApp doesn't seem to support the HTMLBody option,
  • MailApp doesn't seem to be able to send e-mail from an alias.

Did I do something wrong? Did I search the wrong place? Is there a way around this?

11

Both API's, GmailApp and MailApp, have the possibility to send a HTML body via the advanced options. I used below code and was able to send HTML formatted text through both of them.

Code

// global var 
var html =  
    '<body>' + 
      '<h2> Test </h2><br />' +
        '<p> Greetings Earthling </p>' +
    '</body>'    

function testGmailApp() {  
  GmailApp.sendEmail(
    'your@emailaddress.com',         // recipient
    'test GmailApp',                 // subject 
    'test', {                        // body
      htmlBody: html                 // advanced options
    }
  ); 
}

function testMailApp() {
  MailApp.sendEmail(
    'your@emailaddress.com',         // recipient
    'test MailApp',                  // subject 
    'test', {                        // body
      htmlBody: html                 // advanced options
    }
  ); 
}

Screenshot

enter image description here

Reference

  • Thank you! It works wonder well, even with the from: advanced option. I really have no clue what I did wrong in the first place. – Gauwain Jan 20 '14 at 10:18

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