【问题标题】:Auto get Email bot with google scripts使用谷歌脚本自动获取电子邮件机器人
【发布时间】:2020-10-28 23:02:44
【问题描述】:

我正在制作一个机器人来获取第一封电子邮件并将其打印出来。这是我目前所拥有的:

.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index')
}

.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
    function mail() {
    var thread = GmailApp.getInboxThreads(0,1)[0]; // Get first thread in inbox
    thread.getMessages()[0]; 
    }
    function text() {
    var list = document.getElementsByClassName("example")[0];
    list.getElementsByClassName("child")[0].innerHTML = mail();
    }
    </script>
  </head>
  <body>
    <ul class="example">
    <li class="child">Coffee</li>
    </ul>
    <button onclick="text()">Try it</button>
  </body>
</html>

如果您需要任何其他信息,请告诉我有什么问题并发表评论

【问题讨论】:

  • 所以我应该把它放在我的 doGet() 中?
  • 不直接放到服务器上,用google.script.run访问。这整个功能应该是服务器端。function mail() { var thread = GmailApp.getInboxThreads(0,1)[0]; // Get first thread in inbox thread.getMessages()[0]; }ref
  • 好的,我会这样做,但在我尝试访问它之前(“mail()”),它说“抱歉,此时无法打开文件。请检查地址并尝试'

标签: html google-apps-script gmail


【解决方案1】:

html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script>
    function text() {
    google.script.run
    .withSuccessHandler(function(whatever){
       //do whatever your want with whatever here
    })
    .mail() 
    }
    </script>
  </head>
  <body>
    <ul class="example">
    <li class="child">Coffee</li>
    </ul>
    <button onclick="text()">Try it</button>
  </body>
</html>

代码.gs:

    function mail() {
     var thread = GmailApp.getInboxThreads(0,1)[0]; // Get first thread in inbox
     thread.getMessages()[0]; 
     //.......
     return whatever;
    }

这是另一个例子:https://stackoverflow.com/a/60365593/7215091

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-07
    • 2013-04-04
    • 2017-07-31
    • 1970-01-01
    • 2013-11-15
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多