首页 > 解决方案 > 如何阅读 gmail 邮件内容并仅搜索链接,然后将其保存在某处

问题描述

我想编写一个脚本,它读取电子邮件内容,其中将包含一些图像的链接。是否有脚本可以读取消息内容并将此链接保存到 txt 将在 google 驱动器上?

现在我有这个,它以某种方式工作,但会生成 2 个文件。

function test() 
{
  var BouncedEmails = GmailApp.search("label:Inbox .png ");

  for( var i=0;i<BouncedEmails.length;i++)
  {
    var Gmessage = GmailApp.getMessagesForThread(BouncedEmails[i]);

    for(var j=0;j<Gmessage.length;j++)
    {
      var body = Gmessage[j].getPlainBody();
      var fileName,newFile; //Declare variable names
      
      fileName = "Export" + new Date().toString().slice(0,24) + ".txt";//Create a new file name with date on end
      
      newFile = DriveApp.createFile(fileName,body);
    }
  }
}

标签: google-apps-scriptgmail

解决方案


当前脚本生成一个 txt 文件到 Google Drive,其中包含:

https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png 一些东西 https://i.redd.it/9xzdfgdfg8o21.jpg 一些东西 https://i.redd.it/9xwer2342dd8o21.jpg

脚本生成文件的邮件: 示例


推荐阅读