Delete emails from outbox

bharath3014
Kilo Contributor

I want to delete emails from the email log from outbox. Not all the mails, only from outbox i want to delete. Can anyone help me out with the background script to delete the emails from the log.

Thank you very much in advance.

1 ACCEPTED SOLUTION

You can check this out.



var gr = new GlideRecord('sys_email');


gr.addEncodedQuery('mailbox=outbox');


gr.query();


gr.next();


gr.deleteMultiple();


 


Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

14 REPLIES 14

Alikutty A
Tera Sage

Hi Bharat,



You can try this out



var gr = new GlideRecord('sys_email');


gr.addEncodedQuery('mailbox=outbox');


gr.query();


gr.next();


gr.deleteMultiple();



There might be large number of logs in the outbox, Make sure you run it on a lower instance first.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Thank you so much...


Hello Bharat,



If I have answered your query, can you please mark my response as correct answer so we close this thread?



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


vinothkumar
Tera Guru

Hi Bharat,



I tried in our Dev instance and it is working, Can you try the below script.



disableEmails();



function disableEmails() {




  var users = new GlideRecord("sys_email");


  users.addQuery('sys_created_on', '2013-08-15 23:35:28');


  users.query();


    users.deleteRecord();


    while (users.next()) {


users.deleteRecord();




  }


}


Shafi3
Tera Contributor

Only this worked for me where "sys_email" is the outbox table:

var gr = new GlideRecord("sys_email");
gr.query();
gr.deleteMultiple();