Not able to open .msg file in outlook

Pratiksha2
Mega Sage

Currently, I am attaching email to the incident with .msg file extension.

To achieve this I have written one script include.

It's attaching the email to incident with .msg file but when I tried to open it's showing me error.

 

Here is my script include: 

var emailAsAttachmentUtil = Class.create();
emailAsAttachmentUtil.prototype = {
initialize: function() {
this.newLineChar = "\n"; // Microsoft Windows expects \r and \n for return and new line
this.contentType = "application/octet-stream";
},

createAttachment: function (emailRec, currentRec) {
var fileName = emailRec.subject + '.msg';

// Setup array to push email values into. Add additional as needed/
var emailData = [];
emailData.push("To: " + emailRec.to);
emailData.push("Subject: " + emailRec.subject);
emailData.push("From: " + emailRec.origemail);
//emailData.push(emailRec.body_html);
emailData.push('\n'+emailRec.body_text);

// Convert emailData to a string separated by new line character.
var emailString = emailData.join(this.newLineChar);

// Create attachment with email string and attach it to the record creatd by the email.
var sysAttachment = new GlideSysAttachment();
sysAttachment.write(currentRec, fileName, this.contentType, emailString);
},

type: 'emailAsAttachmentUtil'
};

 

 

Here is my ss for more info:

 

Pratiksha2_0-1676871036807.png

 

Thanks in advance.

Regards,

Pratiksha

5 REPLIES 5

newhand
Mega Sage

@Pratiksha2 

It looks so easy to create a  [.msg] file ...

In fact , i  don't think  [.msg] file can be create so easily ...

 

 

 

Can you please provide some more details?

Is anything wrong in script include?

 

 

@Pratiksha2 

I think [.eml] file is the best way ..not [.msg] .

And it looks like you are writing a  [.eml] file.  have a  try to change the file name to [xxxxxx.eml] ?

 

Refer this link  Here 

 

 

 

 

 

But my requirement is to convert the email to .msg file not in .eml