Parsing .eml/.msg email attachments

geoffluk
Tera Contributor

Hi all,

So it's been asked, and answered, whether or not we can parse email attachments that are CSV or Excel file formats. However, we have a business requirement to instead parse .eml or .msg email attachments.

The general purpose of this is to parse the attached .eml/.msg file, check for a specific key-value pair in the HTML body (or in the header) of the attachment, and then process the original inbound email accordingly.

I understand that this is already something that is taken care of by Security Incident / Security Incident Response functionality, but we do not currently use this feature. Right now we need something that is more generic that allows us to handle these .eml and .msg via inbound Incident creation.

 

Thanks!

9 REPLIES 9

Kavi4
ServiceNow Employee
ServiceNow Employee

Hello Geoffluk,

You can use ParseAttachmentAsAnEmail platform api to parse the .eml or .msg email attachments. It will give you a json containing observables.

Example :

var emailJSON = ParseAttachmentAsAnEmail.parse(attachmentGr);

You can retrieve info from emailJSON as listed below

  • emailJSON.headers()
  • emailJSON.body_html
  • emailJSON.body_text
  • emailJSON.subject
  • emailJSON.from() 
  • Get file/sha256 from attachments

for (var i = 0; i < emailJSON.parts().length; i++) {
       some var = processing    emailJSON.parts()[i]);
}

Hi Kavi,

I tried to use your code but I'm getting an error for using "ParseAttachmentAsAnEmail" the error is "

"ParseAttachmentAsAnEmail" is not defined." 
What I'm doing wrong?
Thanks,
Lior grinberg

Hi @lior grinberg ,

I'm facing the same issue, were you able to find the issue?

Hi,

I solved the problem with a different command.

I created a small project in Share for that.

You can download it and look on the solution there:

https://developer.servicenow.com/connect.do#!/share/contents/8295848_undelivered_email?v=1.0&t=PRODUCT_DETAILS

Best rgerads,

Lior grinberg