An "infinite email" loop occurs when an update to a record triggers a notification that sends an email to an external recipient.

The receipt of that email on the external system can trigger an automatically generated reply, which is then sent back to ServiceNow. 

When we process that email, it may be added to the comments or work notes of the record, thus triggering another update that sends another email to the external recipient, therefore causing an infinite loop.


Solution 1

Ignoring emails with the Auto-Submitted:auto-generated header

The first solution is to simply ignore emails that are generated with the "Auto-Submitted:auto-generated" header. 

You can modify email properties by navigating to either the System Mailboxes > Administration > Email Properties module or the System Properties > Email Properties module, or by navigating to the / list and searching for the glide.pop3.ignore_headers system property. 

This system property is a string and the default value is:

Ignore mail with these headers (comma separated name:value pairs)
X-ServiceNow-Spam-Flag:YES,X-ServiceNow-Virus:INFECTED,Auto-Submitted:auto-replied,X-ServiceNow-Generated:true,X-FC-MachineGenerated:true,Content-Type:multipart/report; report-type=delivery-status;

Please note that this string already shows "Auto-Submitted:auto-replied", but not "Auto-Submitted:auto-generated".  We can add this to the string, though:

Ignore mail with these headers (comma separated name:value pairs)
X-ServiceNow-Spam-Flag:YES,X-ServiceNow-Virus:INFECTED,Auto-Submitted:auto-replied,Auto-Submitted:auto-generated,X-ServiceNow-Generated:true,X-FC-MachineGenerated:true,Content-Type:multipart/report; report-type=delivery-status;

This will ignore the auto-generated emails and avoid the infinite loop.

Solution 2

Disabling Workflow when updating the comments of the target record

Another solution is, when you have a script (such as an "Inbound Email Action" [sysevent_in_email_action] script) that is processing the inbound email, don't trigger business rules / workflows when you update the target record. 

For example:

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
if (current.getTableName() == "incident") {
current.comments = "Reply From: " + email.origemail + "\n\n" + email.body_text;
})(current, event, email, logger, classifier);

This will update the target record with the comments, but it will avoid triggering the business rules that again trigger the notification.

Solution 3

Modify the "Ignore header" Email Filter

Similar to setting the glide.pop3.ignore_headers system property, we can create or modify an email filter via the System Mailboxes > Administration > Filters module.

There is an out-of-the-box filter named "Ignore header" that ignores emails that contain these headers:

  • Auto-Submitted:auto-replied
  • X-ServiceNow-Generated:true
  • X-FC-MachineGenerated:true
  • Content-Type:multipart/report; report-type=delivery-status;

You can click on the OR button and add another condition that ignores the emails with headers that contain "Auto-Submitted:auto-generated":

Additional Information

Article Information

Last Updated:2020-08-11 08:37:50