0

可以请教你的意见吗。我有一个执行此操作的 Google 脚本:1)检查是否有任何用星号标记的对话 2)如果有,请取消选择它,然后将此对话转发到该地址

它运作良好,但我需要轻松拉皮条。而不是转发,我需要将消息发送到地址,这将是报告的主题,并在找到消息的线程链接下找到消息正文的消息正文,并且锦上添花一直引用邮件中的附件。

    function TJ() {
  var threads = GmailApp.search('is:starred');
  for (var h = 0; h < threads.length; h++) {
    var messages = threads[h].getMessages();
    for (var i = 0; i < messages.length; i++) {
      if (messages[i].isStarred())
      {
        Logger.log(messages[i].getSubject());
        messages[i].unstar();
        messages[i].forward("--email-address--", {
          cc: "",
          bcc: ""
          });     
      }
  }
}
}

谢谢!

4

3 回答 3

3

太棒了!

function AddSM2GTDApp() {
      var threads = GmailApp.search('is:starred');
      for (var h = 0; h < threads.length; h++) {
        var messages = threads[h].getMessages();
        for (var i = 0; i < messages.length; i++) {
          if (messages[i].isStarred())
          {
            Logger.log(messages[i].getSubject());
            var subject = messages[i].getSubject();
            Logger.log(messages[i].getBody());
            var body = messages[i].getBody();
            Logger.log(messages[i].getId());
            var id = messages[i].getId();
            var label = GmailApp.getUserLabelByName("Add2GTDApp");
            threads[h].addLabel(label);
            messages[i].unstar();
            MailApp.sendEmail({
         to: "your@email.com",
         subject: subject,
         htmlBody: "https://mail.google.com/mail/u/0/#inbox/"+id+"<br>--------------------------------------------------------------------------------------<br>"+body+"<br>--------------------------------------------------------------------------------------<br>Mail to Nirvana Script ",
       }); 
          }
      }
    }
    }
于 2013-07-17T11:48:19.507 回答
0

function autoForwardZoom() {
  var s = "";
  var m = "";
  var c = 0;
  var a = "";
  var f = "";
  var label = 'IT/Zoom';
  var subject = 'Disconnected';
  var from = 'no-reply@domain.us';
  var threads = GmailApp.search("from:" + from + " label:" + label + " is:unread subject:(" + subject + ")", 0, 1);
  for (var i = 0; i < threads.length; i++) {
    var message = threads[i].getMessages();
    c = threads[i].getMessageCount() - 1;
    m = threads[i].getMessages()[c];
    b = m.getBody();
    s = m.getSubject();
    a = m.getAttachments();

    var returnData = [];
    var html = HtmlService.createTemplateFromFile('Temp');

    html.data = returnData;
    var template = html.evaluate().getContent();

    m.forward("youremail@gmail.com", {
      replyTo: "myemail@gmail.com",
      subject: s,
      htmlBody: template + "<br>" + b,
      attachments: a
    });
    GmailApp.markThreadsRead(threads);
  }

}

我的 HTML 模板,

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
<div>Dear Team</div>
<div>&nbsp;</div>
<div>Please kindly check zoom controller issue</div>
<div>&nbsp;</div>
<div>Regards</div>
<div><i>please reply this email with word "SOLVED" to earn credits, once you has solved this issue</i></div>
<div>&nbsp;</div>
<div style='text-align: center;'>---------- Forwarded message from Zoom ----------</div>
  </body>
</html>

于 2019-10-11T10:07:17.250 回答
0

请尝试以下代码,您可以添加 5 分钟时间驱动的事件触发器来运行脚本

function MailForward() {

try{
var glabel = createLabel_("Mail-Forwarded");
var rtm_email = 'abc@abc.com';
var from_email = Session.getActiveUser().getEmail();
var threads =  GmailApp.search('in:inbox is:unread newer_than:1d');
var mForward = 0;

for (var i=0;i<threads.length;i++) {

  var messages=threads[i].getMessages();
  for (var m = 0; m < messages.length; m++){
    if (messages[m].isUnread()){

    mForward = 0;  
    var mlabels = threads[i].getLabels();
    for (var j = 0; j < mlabels.length; j++) {
      Logger.log(mlabels[j].getName());

      if (mlabels[j].getName() === "Mail-Forwarded") {
      mForward = 1;  
      }
    }

    if (mForward===0) {

    //   Logger.log(messages.length)
    //   Logger.log(messages[m].getFrom());
    var from = messages[m].getFrom();

    //Logger.log(messages[m].getDate());
    var date = messages[m].getDate();

    // Logger.log(messages[m].getSubject());
    var subject = messages[m].getSubject();

    //  Logger.log(messages[m].getTo());
    var to = messages[m].getTo();

    var body = messages[m].getBody();
    var attachment = messages[m].getAttachments();

    var emailoptions = ("---------- Forwarded message ----------" +'<br>'+'From: '+from+ "<'" + from.replace(/^.+<([^>]+)>$/, "$1") +"'>"+'<br>'+ 'Date: '+date+'<br>'+ 'Subject: ' +subject+'<br>'+ 
                    'To: ' +to+ "<'" + to.replace(/^.+<([^>]+)>$/, "$1") +"'>"+'<br>'+'<br>'+'<br>');

    messages[m].forward(rtm_email,{htmlBody: emailoptions + body , Attachment: attachment});

    glabel.addToThread(threads[i]);
    Logger.log(glabel.getName());
    messages[m].markRead();

    mForward = 1;

      }
    }
  }
}
} catch(e) {

 MailApp.sendEmail("abc@abc.com", "Exception found in Sript", e );
  Logger.log(e);

}
}
于 2016-04-21T09:05:32.530 回答