Reputation: 3110
I had a script working with plaintext, but not having any luck with HTML formatting. with variables email
, SUBJECT
, and MESSAGE
defined, I think this may work:
MailApp.sendEmail(email, SUBJECT, {htmlBody: MESSAGE});
The email sends as expected with the given subject, but the only information is "[object Object]" in plaintext.
I'm clearly messing up the syntax here, but I can't seem to reverse engineer how they did it in this tutorial.
Thanks!
Upvotes: 1
Views: 5475
Reputation: 5795
var options = {};
options.name = "Some display name";
options.replyTo = "[email protected]";
options.htmlBody = "<b>An HTML message</b>";
MailApp.sendEmail("[email protected], title, "Plain text in case the receiver can't render HTML", options);
Personally I create an options
Object that I pass to the sendEmail()
method of the MailApp class. This way it's a bit easier to manage your extra parameters like HTML content.
However, you really should have read the documentation, which clearly states the multiple methods of sending an email. You want to send HTML content, so you need to use the method that takes the optional parameter. The optional parameter is an Object which has multiple key/value pairs that are used to further specify, well, options for the sent email.
Upvotes: 1