I'm writing an auto-replying bot for gmail using Google Apps Script (http://script.google.com). Each time I use GmailThread
's Reply
to reply to message:
var htmlbody = "Hello<br>This is a <b>test</b>.<br>Bye.";
var body = "Hello,\nThis is a test.\nBye.";
thread.reply(body, {htmlBody: htmlbody, from: "Myself <hello@example.com>"});
I need to write the message both in plain text body
and HTML in htmlbody
.
Would there be a way to write an email only in HTML (to avoid writing every email content twice, plain and HTML!), and let reply()
automatically send the email both in HTML and plaintext version?
I tried
var body = htmlbody.replace(/<br>/g,'\n').replace(/<b>/g,'');
// we should also replace </b> by '', etc.
but this is a bit of a hack. Is there a better version?
/g,'\n').replace(/<.+?>/g, "");` would be useful as well? – Basj Aug 25 '17 at 14:45