Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9704

Sending an email with just an attachment with script

$
0
0

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  }}

Viewing all articles
Browse latest Browse all 9704

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>