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

Anurag Tripathi
Mega Patron
Mega Patron

Id suggest that you write the script and if it doesnt work then post it here and we can help you improve it. good for your own learning as well.



Basically you want to query the sys_email_list table and apply the query 'mailbox=outbox' and whatever qualifies you delete it   (deleteMultiple())


-Anurag

Hi Anurag,



Thank you for your reply. below script is to delete the yesterday record. If i want to delete outbox. can you please modify this script and help me in this.



var email = new GlideRecord('sys_email');  


email.addEncodedQuery('sys_created_onONYesterday@javascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(1)');  


email.query();  


while(email.next()){  


email.deleteRecord();  


}


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


var email = new GlideRecord('sys_email');


email.addEncodedQuery('sys_created_onONYesterday@javascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(1)^mailbox=outbox');


email.query();


while(email.next()){


email.deleteRecord();


}



Before running this you might just want to print it once just to be sure that the filters are right.




and then delete.


-Anurag