Recognizing the Original Sender of a Forwarded email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2018 11:49 AM
So i'm using my free dev instance and working on starting 'tickets' (cases) from an email. I've got the inbound email action working for one sent from an email, so there's no issue there. The issue i'm having is dealing with the forwarded email. I've created the inbound email action (forwarded email) and got it to populate a my Submitted By field from the forwarded email. One I can't get to work is when the email has been forwarded more than once to get the user information from the original email.
This line works for the email only being forwarded once:
current.submitted_by = email.body.from.split("<")[0];
I would greatly appreciate any help with configuring it to pull the user from the original email for situations (though highly unlikely) where the email has been forwarded an additional x number of times before getting to the servicenow instance.
-
Joe
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 10:42 AM
Fixed it with this:
var emailBody = email.body_text; //Get email body as text
var originalSenderIndex = emailBody.indexOf("From:"); //Get the index of the first forward sender
while(emailBody.indexOf("From:", originalSenderIndex + 1) != -1){ //Continue to itterate thorugh the senders until the original is found
originalSenderIndex = emailBody.indexOf("From:", originalSenderIndex + 1); //Update the sender index
}
var originalSenderLine = emailBody.substring(originalSenderIndex, emailBody.indexOf("\n", originalSenderIndex)).split(" "); //Get the full text line that the original sender is on
current.requestor.setDisplayValue(originalSenderLine[1] + " " + originalSenderLine[2].split("<")); //Set the requestor field
Now i'm trying to see if the system will recognize the 'importance' from the original email. I've got it working on an email going directly to the instance but i'm having issues with it when it's forwarded.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2021 04:00 AM
Hi Joe,
I have a similar requirement in our work,
we actually need the original sender's email address but here with this, I'm getting the original sender's name.
Is there any way to achieve this?
Any suggestions would be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2021 07:44 AM
I believe you should be able to get it using a RegEx: /(?<=<).*(?=>)/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 03:24 PM
This is what worked for me.
var str = email.body.from;
var mySubString = str.substring(
str.lastIndexOf("<") + 1,
str.lastIndexOf(">")
);
current.opened_for = mySubString;
current.opened_by = mySubString;