Attaching inbound email to ticket in .msg format

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 06:53 PM
We would like to attach the actual original email that is sent to our instance to the created ticket - the best we have been able to do so far is attach the source email in plain text .eml format. Does anyone have a similar requirement or have been able to achieve the outcome?
Here is the script we're using:
/**
* This creates an converts the email to be an attachment on the record passed in
* At the moment it only works with Plain text - as I could not get it working otherwise!
* To use this in an inbound email, use the following code.
*
* var emailUtilsObj = new APIEmailUtilities();
* emailUtilsObj.makeEmailAsAttachment(email, current);
*
* @param {Object} _emailObj - The sys_email object used in bound actions
* @param {GlideRecord} _currentRec - The record we want to attach this to.
*
* @return {nothing}
*/
APIEmailUtilities.prototype.makeEmailAsAttachment = function(_emailObj, _currentRec) {
var sysAttachObj = new GlideSysAttachment();
//Make the file name - needs to be text/plain or won't work.
var fileNameStr = String(_emailObj.subject) + '.eml';
var contentTypeStr = 'text/plain';
var emailStr = '';
emailStr += 'To: ' + _emailObj.to + '\n';
emailStr += 'Subject: Re: ' + _emailObj.subject + '\n';
emailStr += 'From: ' + _emailObj.origemail + '\n';
emailStr += 'Reply-To: ' + _emailObj.origemail + '\n';
emailStr += _emailObj.body_text;
//Attach the email to the current record.
var sysIdNewAttachment = sysAttachObj.write(_currentRec, fileNameStr, contentTypeStr, emailStr);
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 07:03 AM
Hi Warren,
It is good to know that you were able to change the source email format to .eml. As original email attachment will not be attached to the ServiceNow cases. Please update here if you are able to get the original attachment with original name and format to the ServiceNow tickets.You can try glide recording the sys_attachement table and check it with corresponding sys_log email. But it might cause performance issue to glide record on email log table.
I had tried to achieve this requirement but I stopped due to the impact and other constrains (which I don't remember now). Thanks to you I will try again.
Please let me know if you need more details.
Regards,
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2018 05:58 AM
Hi Warren,
We have similar requirement and I was trying to use your code but I am unable to attach the source email in plain text .eml format. Could you please explain how can we include this script in inbound action.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2018 02:48 PM
Hi all,
I am also trying to attach a copy of the original email to the ticket that is opened by the inbound action. I've tried the above code but it doesn't seem to be working for me. Has anyone been able to get this to function?
Thanks,
Sarah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2018 11:16 AM
There have been a few others asking for the capability. I improved @warrem's code and created a Blog post outlining steps to create this functionality in your instance:
https://community.servicenow.com/community?id=community_blog&sys_id=94ebc947db621b002be0a851ca961921