- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2023 08:29 AM - edited 03-28-2023 11:07 AM
How to create a email record using .eml file attachment or retrieve .eml file content in ServiceNow using MailParser() package or anyother available methods..
Please advise.
Thanks,
Sumanth Bolle
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 10:56 AM - edited 03-30-2023 01:57 AM
Please try below custom script :
var Attachment = new GlideSysAttachment().getContentStream('8ea76e761b3da9540af564e0b24bcb71'); // attachment sys_id of .eml file
var reader = new GlideTextReader(Attachment);
var line = '';
var str = '';
while ((line = reader.readLine()) != null) {
var htmlValue = "";
if (GlideStringUtil.isBase64(line)) {
htmlvalue = GlideStringUtil.unEscapeHTML(GlideStringUtil.base64Decode(line));
} else {
htmlvalue = GlideStringUtil.unEscapeHTML(line);
}
var check = htmlvalue.contains(" ");
str += htmlvalue;
}
//gs.info(str);
var bodyStart = str.indexOf('<head>');
var bodyEnd = str.indexOf('</html>');
var bodyOutput = "";
if (bodyStart != -1) {
bodyOutput = '<html>' + str.substring(bodyStart, bodyEnd).trim() + '</html>';
} else {
bodyOutput = str;
}
gs.info(bodyOutput);
Please mark as helpful and let me know if there's any issue in formatting..
Best regards,
Sumanth Bolle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2023 10:56 AM - edited 03-30-2023 01:57 AM
Please try below custom script :
var Attachment = new GlideSysAttachment().getContentStream('8ea76e761b3da9540af564e0b24bcb71'); // attachment sys_id of .eml file
var reader = new GlideTextReader(Attachment);
var line = '';
var str = '';
while ((line = reader.readLine()) != null) {
var htmlValue = "";
if (GlideStringUtil.isBase64(line)) {
htmlvalue = GlideStringUtil.unEscapeHTML(GlideStringUtil.base64Decode(line));
} else {
htmlvalue = GlideStringUtil.unEscapeHTML(line);
}
var check = htmlvalue.contains(" ");
str += htmlvalue;
}
//gs.info(str);
var bodyStart = str.indexOf('<head>');
var bodyEnd = str.indexOf('</html>');
var bodyOutput = "";
if (bodyStart != -1) {
bodyOutput = '<html>' + str.substring(bodyStart, bodyEnd).trim() + '</html>';
} else {
bodyOutput = str;
}
gs.info(bodyOutput);
Please mark as helpful and let me know if there's any issue in formatting..
Best regards,
Sumanth Bolle