google Apps script using mailApp to send htmlbody (content being modified)

Viewed 134

I was trying to send an approval letter with google apps script (mailApp). And hide some data in the hidden input. However, the id of the input was changed by google.

The script in google apps script:

MailApp.sendEmail({
    to: email,
    subject: "Classroom register Approval",
    body: "",
    htmlBody: 
      "<form action = 'google apps script website' method = 'POST'>" +
      "<input id='approverow' type='hidden' value="+ e.range.getRowIndex() +">" +
      "<button type = \"submit\">Approve</button>"
  })

real HTML in email

<form action="google apps script website" method="POST" target="_blank">
<input id="m_8985313804230818410approverow" type="hidden" value="22">
<button type="submit">Approve</button></form>

Why Google change the element id and how can I stop it?

1 Answers

Issue:

I think the id is only getting modified when being displayed in the corresponding INBOX, but it's not modified in the message itself.

Explanation:

As you probably know, the id of an element must be unique in the whole document. So I think this is a way to ensure that the id is unique in the page in which it is being displayed (e.g. INBOX). Think, for example, what would happen if the id you specified matched the one in Gmail sidebar?

More importantly, you can notice that if you retrieve the message body once it has been sent (via GmailApp.search, or what have you) the id of the message is the one you specified, no modification.

Also, this is not particular to Google: you can check that the id gets modified in different ways depending on where the email is being displayed. While messages displayed in Gmail INBOX get appended something like m{many numbers}, messages displayed in Outlook get appended x_. And a similar behaviour seems to occur for the class attribute: in Outlook, class attributes from the email body also get x_ appended, while in Gmail, class is not even present.

Related