title: Google Scripts Auto-Forward for Google Inbox
body: <p>I used this code for Gmail but now I am looking to do something similar for Google Inbox. The problem is that Google Inbox does not support labels, so I have to come up with another solution. Perhaps somehow check emails inside a container every 5 minutes and then forward them? Any other suggestions?</p>
  
  <pre><code>function autoForward() {
    var label = 'ForwardThis';
    var recipient = 'domain@forward.domain.com';
    //  if the script runs every 5 minutes; change otherwise
    var interval = 5;          
    var date = new Date();
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('label:' + label + ' after:' + timeFrom);
    for (var i = 0; i &lt; threads.length; i++) {
      var messages = threads[i].getMessages();
      var from = messages[i].getFrom();
      var subject = messages[i].getSubject();
      var to = messages[i].getTo();
      var attachment = messages[i].getAttachments();
      var body = messages[i].getBody();
      for (var j = 0; j &lt; messages.length; j++) {
        var emailoptions = (
          "---------- Forwarded message ----------" + '&lt;br&gt;' +
          'From: ' + from + "&lt;'" + from.replace(/^.+&lt;([^&gt;]+)&gt;$/, "$1") + "'&gt;" + '&lt;br&gt;' +
          'Date: ' + date + '&lt;br&gt;' +
          'Subject: ' + subject + '&lt;br&gt;' +
          'To: ' + to + "" + '&lt;br&gt;' + '&lt;br&gt;' + '&lt;br&gt;'
        );
        messages[j].forward(recipient,{htmlBody: body + emailoptions, Attachment: attachment});
      }
    }
  }
  </code></pre>