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.