如何使用GAS显示电子邮件内容 [英] How to show an email message content using GAS
问题描述
var email = GmailApp 我获得了一封电子邮件的ID,并希望显示电子邮件内容(html)。 .getMessageById(ID);
如何通过打开新的浏览器窗口显示电子邮件
a)或在选项卡式浏览器中输入标签)
$ p
$) >关于c)我知道我可以使用
var body = email.getBody();
app.createHTML()。setHTML(body);
但这消除了很多元素(如图片和链接)
编辑-1
通过打开Gmail和消息,部分回答 b)为通过使用可弯曲的锚点并点击它
var mailUrl ='https://mail.google.com/mail/ ?U / 0 /选项卡= OM#收件箱/';
var urlAnchor = mailUrl + message.getId();
var btn = app.createAnchor(row,urlAnchor)
但这需要用户点击
,即使可以使用由锚点覆盖的按钮图像(请参阅如何从一个按钮启动一个网站)我不太喜欢这个
EDIT-1a
确实使用锚点最快。
var urlImage ='https://drive.google.com/uc?id=0BxjtiwHnjnkraTN3UmN6NDhrSDA'; //空按钮图像
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 +')');
添加clickHandler(到网格或锚点)允许记录和其他事情。
一件事(通常)不需要将会改变背景图像。我尝试过(并且工作正常),但事实证明,在打开邮件之前我甚至没有看到更改后的图像。
这种方法的缺点是您不断看到锚点文本的下划线,并且只能点击锚点占用的区域。
EDIT-2
我应该提到我正在使用 UiApp.createApplication();
并且正在寻找一种可能性来显示来自UiApp的电子邮件。
这将不可能使用UiApp HTML小部件。 HTML小部件仅允许有限数量的html标签( 2012年3月7日发行说明)
以下是允许使用的HTML标签列表: 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 b 可能的解决方法是在另一个浏览器页面(使用html服务)中呈现该消息并链接到该页面。 I obtained an id of an email message and want to display the emails content (html). how can I display the email Regarding c) I know I can use but this removes a lot of elements (like pictures and links) Edit-1 But this requires the user to click EDIT-1a Adding a clickHandler (to the grid or the anchor) allows logging and other things. 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 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. 这篇关于如何使用GAS显示电子邮件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b var email = GmailApp.getMessageById(id);
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 var body = email.getBody();
app.createHTML().setHTML(body);
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)
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
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 + ')');
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.
I should have mentioned that I'm using UiApp.createApplication();
and am looking for a possibility to show an email from within a UiApp.