45094

How to show an email message content using GAS

Question:

I obtained an id of an email message and want to display the emails content (html).

var email = GmailApp.getMessageById(id);

how can I display the email<br /> a) by opening a new browser window (or tab in a tabbed browser)<br /> b) by opening Gmail and the message<br /> c) by showing it in a Ui widget

Regarding c) I know I can use

var body = email.getBody(); app.createHTML().setHTML(body);

but this removes a lot of elements (like pictures and links)

<strong>Edit-1</strong><br /> A partial answer to b) by opening Gmail and the message is by using an anchor in a flextable and clicking it

var mailUrl = 'https://mail.google.com/mail/u/0/?tab=om#inbox/'; var urlAnchor = mailUrl + message.getId(); var btn = app.createAnchor(row, urlAnchor)

But this requires the user to <strong>click</strong><br /> even though it is possible to use an image of a button overlayed by an anchor (see <a href="https://stackoverflow.com/questions/22869831/how-can-i-launch-a-website-from-a-button/23634444#23634444" rel="nofollow">How can I launch a website from a button</a>) I don't really like this

<strong>EDIT-1a</strong><br /> Using an anchor for sure is fastest.

var urlImage = 'https://drive.google.com/uc?id=0BxjtiwHnjnkraTN3UmN6NDhrSDA'; // Empty button image var anchor = app.createAnchor(txtAnchor, urlAnchor) .addClickHandler(onClickHandler) .setSize(width-2, height-2); var grid = app.createGrid(1, 1).setWidget(0, 0, anchor) .setSize(width, height).setStyleAttribute('textAlign', 'right') .setStyleAttribute('backgroundImage', 'url(' + urlImage + ')');

Adding a clickHandler (to the grid or the anchor) allows logging and other things.<br /> One thing (usually) NOT needed will be changing the backgroundimage. I tried (and it works), but it turned out I didn't even see the changed image before the mail will be opened.

Disadvantages of this approach are that you keep seeing the underline of the anchortext and that only the area occupied by the anchor can be clicked

<strong>EDIT-2</strong><br /> I should have mentioned that I'm using UiApp.createApplication(); and am looking for a possibility to show an email from within a UiApp.

Answer1:

This won't be possible using UiApp HTML widget. The HTML widget only allows a limited number of html tags (<a href="https://developers.google.com/apps-script/releases/2012" rel="nofollow">release note march 7, 2012</a>)

Here is the list of HTML tags that are permitted: <strong>B, BLOCKQUOTE, BODY, BR, CENTER, CAPTION, CITE, CODE, DIV, EM, H1, H2, H3, H4, H5, H6, HR, I, LABEL, LEGEND, LI, OL, P, SPAN, STRONG, SUB, SUP, TABLE, TBODY, TD, THEAD, TITLE, TR, TT, UL</strong>

A possible workaround would be to render that message in another browser page (using html service) and link to that page.

Recommend

  • apache poi: how to create chart with both bar and line?
  • How to parse nested JSON with GSON
  • What should be the grok pattern for thoses logs ? (ingest pipeline for filebeat)
  • Add foreach value to Ajax
  • Angular transclude in a directive containing a ng-template (generic Confirm Modal)
  • How to Set wallpaper of image with its actual size?
  • Mapping ManyToMany with composite Primary key and Annotation:
  • Eventbus onMessageEvent not getting called
  • Creating a Multi-Step Modal Using Jquery
  • python: forcing relative imports to search from script file
  • Jquery popup on mouse over of calendar control
  • Button text different than value submitted in query string
  • Firefox Extension - Monitor refresh and change of tab
  • Alternative to overridePendingTransition() - Android
  • Is there a perl module to validate passwords stored in “{crypt}hashedpassword” “{ssha}hashedpassword
  • Rails Find when some params will be blank
  • MongoError: Incorrect arguments
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Python urlparse: small issue
  • Dialing with Intent.ACTION_CALL stopps at # in phone number
  • Highlight one bar in a series in highcharts?
  • FileReader+canvas image loading problem
  • Lost migrations and Azure database is now out of sync
  • Is there any way to access browser form field suggestions from JavaScript?
  • Android screen density dpi vs ppi
  • Dynamically accessing properties of knockoutjs observable array
  • script to move all files from one location to another location
  • WinForms: two way TextBox problem
  • Can I make an Android app that runs a web view in Chrome 39?
  • Unanticipated behavior
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • python draw pie shapes with colour filled
  • Can't mass-assign protected attributes when import data from csv file
  • Does armcc optimizes non-volatile variables with -O0?
  • Busy indicator not showing up in wpf window [duplicate]
  • Unable to use reactive element in my shiny app
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF