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)
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
I should have mentioned that I'm using
UiApp.createApplication(); and am looking for a possibility to show an email from within a UiApp.
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.