Here is my script for forwarding emails to another inbox. However, now I want to only send emails that are unread with attachments to one email and then if no attachment to a different email. Can someone help me? I believe I would have to put something in the gmailapp.search about attachments, but I can't figure it out. I'm very green around the ears with this.
function AutoForward() { //send response email var threads = GmailApp.search("to:br@345.com is:unread,is:attachment=true"); var subject = ""; var msg = ""; var c = 0; // will be used to count the messages in each thread var t = ""; var attachment = ""; var forwarded = ""; for (var i = 0; i < threads.length; i++) { // I set 'i' to 3 so that you can test the function on your 3 most recent unread emails. // to use it on all your unread email, remove the 3 and remove the /* and */ signs.t = threads[i]; // I wanted to avoid repetition of "threads[i]" for the next 2 lines hahac = t.getMessageCount() - 1;msg = t.getMessages()[c];forwarded = msg.getBody(); // that is the body of the message we are forwarding.subject = msg.getSubject();attachment = msg.getAttachments();msg.forward("a@1234.com", { replyTo: "mail@abc.com", //htmlBody: "" //adds your message to the body //+ //"<div style='text-align: center;'>---------- Forwarded message ----------</div><br>" + forwarded, //centers attachments: attachment}); t.markRead(); // mark each forwarded thread as read, one by one }}