Clean up emails from sys_email table

Khanna Ji
Tera Guru

Hi,

I have tested some functionality on Dev and want to enable outgoing emails but there are pilled up emails which should not be sent out.

What is your suggestion? Delete them or change their status to something so they can be ignored? What script background should be used?

 

Can I use below script to prevent sending the emails existing already in the system?

 

var rec = new GlideRecord('sys_email');
rec.addQuery('type','send-ready');
rec.query(); 
while (rec.next()) { 
   rec.type = 'send-ignored';
   rec.update();
}
1 ACCEPTED SOLUTION

Both of the above "processed, send-gnore" is fine. Sytem will only pick sent ready emails for sending out. You can use the code which you shared, it will prevent the emails from sending out. -satheesh

View solution in original post

5 REPLIES 5

sachin_namjoshi
Kilo Patron
Kilo Patron

You can configure table in auto clean up job.

 

https://docs.servicenow.com/bundle/london-application-development/page/administer/auto-test-framework/concept/table-cleanup.html

 

Regards,

Sachin

Is it anyway related to the context of my question?

You modified  your original question.

Of course, answer will depend on your question.

 

Anyway,  for your current question, you should mark pending emails as processed so that email engine doesn't pick up them again.

 

 

var rec = new GlideRecord('sys_email');
rec.addQuery('type','send-ready');
rec.query(); 
while (rec.next()) { 
   rec.state= 'processed';
   rec.update();
}

 

 

Regards,

Sachin

Do you think, system will send email even if the state is send ignored? Why my script cannot work here?