How to use email reply separators?

kkrushkov
Mega Sage

Hello, Team!

I've been searching but haven't found any information on how to use email reply separators [sys_email_reply_separator] in an email inbound action script. Can anyone provide guidance or examples on this?

Thanks in advance!

Best regards,
KK

8 REPLIES 8

I've already checked all available resources but haven't found any information.

Rajesh Chopade1
Mega Sage

Hi @kkrushkov 

 

Here’s how you can utilize email reply separators in an email inbound action script in ServiceNow:

Steps to Use Email Reply Separators

  1. Understand Email Reply Separators: The sys_email_reply_separator table in ServiceNow stores the reply separators that the system uses to identify and strip quoted text and signatures from incoming emails.

  2. Access and Review Reply Separators: Navigate to System Mailboxes > Administration > Email Reply Separators to review or modify the existing separators. ServiceNow comes with some default separators, but you can customize this list according to your organization's needs.

  3. Inbound Email Action Script: When writing an inbound email action script, you can leverage the EmailUtil class provided by ServiceNow to parse the email content and strip out the text based on the reply separators.

Example Script in an Inbound Email Action:

Here’s an example of how you can write a script to use the email reply separators to process incoming emails:

  1. Navigate to: System Policy > Inbound Actions.
  2. Create a New Inbound Email Action or edit an existing one.
  3. Configure the Conditions as needed to trigger the action.
  4. In the Script section, use the following script to handle the email content:

 

(function runInboundEmailAction(email, action, event) {
    // Import the EmailUtil class
    var emailUtil = new EmailUtil();

    // Get the plain text body of the email
    var bodyText = email.body_text;

    // Use EmailUtil to strip quoted text based on the reply separators
    var cleanBody = emailUtil.extractReplyText(bodyText);

    // Log the clean body for debugging (optional)
    gs.log("Cleaned Email Body: " + cleanBody);

    // Process the cleaned email body as needed
    // For example, create or update an incident with the clean body text
    var incident = new GlideRecord('incident');
    incident.initialize();
    incident.short_description = email.subject;
    incident.comments = cleanBody;
    incident.caller_id = email.originator; // Set the caller to the email sender
    incident.insert();

})(email, action, event);

 

Customizing Reply Separators:

If you need to add custom reply separators, follow these steps:

  1. Navigate to: System Mailboxes > Administration > Email Reply Separators.
  2. Click New to add a new separator.
  3. Define the Separator:
    • Separator: Enter the text or pattern that identifies the beginning of quoted text or signatures.
    • Active: Ensure the separator is active.

I hope my answer helps you to resolve your issue, please mark my answer as correct & helpful then.

 

thank you

rajesh chopade

Hello, @Rajesh Chopade1,

 

Unfortunately, the provided solution isn't working for me. Firstly, I don't have the extractReplyText method out-of-the-box. Secondly, I can't see where to specify the email reply separator from the table.

 

Could you please provide further guidance?

 

Thank you!