0

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
a) by opening a new browser window (or tab in a tabbed browser)
b) by opening Gmail and the message
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)

Edit-1
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 click
even though it is possible to use an image of a button overlayed by an anchor (see How can I launch a website from a button) I don't really like this

EDIT-1a
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.
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

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

Community
  • 1
  • 1
SoftwareTester
  • 1,048
  • 1
  • 10
  • 25
  • you might be interested in [this post](http://stackoverflow.com/questions/22236558/is-there-a-way-to-save-html-text-to-a-file-in-google-drive-using-apps-script) that provides a way to convert html content to Google Doc keeping all formatting. Anyway, it's always good to know ;-) – Serge insas Jul 30 '14 at 22:17
  • Indeed. One of the important things missing is the ability to create "standard" files from google docs (docs, scripts, spreadsheets, calendar .....). Even though cloud storage will become more and more popular, people want (/ need) to have and store data locally and use other programs (and clouds) . Conversion from google spreadsheets to xls, from google docs to msword, etc are very important and should be available as funtions like 'var xlsFile = convert(GoogleSpreadSheetFile, nameExcelFile);' – SoftwareTester Jul 31 '14 at 07:44

1 Answers1

0

This won't be possible using UiApp HTML widget. The HTML widget only allows a limited number of html tags (release note march 7, 2012)

Here is the list of HTML tags that are permitted: 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

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

Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • How can I use html service for doing that? – SoftwareTester Jul 30 '14 at 15:06
  • use the html string you get from the message and render it using https://developers.google.com/apps-script/reference/html/html-output#setContent(String) – Serge insas Jul 30 '14 at 15:17
  • 'function doGet() { return HtmlService.createHtmlOutput().setContent('Hello, world!'); }' does work, but not from within a UiApp (I changed the question to indicate I'm using UiApp) – SoftwareTester Jul 30 '14 at 17:52
  • Yes I know, I suggested that in another browser tab. In UiApp this is actually not possible, as I said in my answer. Your solution using an anchor would be the simplest except if you admit to loose the formatting and show only the text content but I would understand that you don't feel like doing so. – Serge insas Jul 30 '14 at 17:56
  • 1
    I already searched for an answer before, but HOPED I was missing something. Your comment ends my search (for now : i'm sure at some point I will TRY something again....)as I can't think of a solution. Thanks (again) – SoftwareTester Jul 30 '14 at 18:03