How to attach whole email as a attachment to the record in inbound action

SSA1
Giga Expert

Hi,

 

I have a issue when trying to attach the email as an attachment to the record in inbound action.

Please someone guide me for this.

 

var strEmailContent = email.content_type +"\n"+ email.headers + "\n\n\n\n"+ email.body;
var sa = new GlideSysAttachment();

sa.write(current, email.subject +".eml", "application/octet-stream ", strEmailContent);
current.insert();

 

but this was not working. can someone please help me with this.

 

For anyone who is facing this issue I was  able to figure out the issue and I will update the correct code below.

 

var attachment = new GlideSysAttachment();
var fileName = email.subject + '.eml';
 var contentType = 'application/octet-stream';
var content = email.content_type + "\n" + email.headers + "\n\n\n\n" + email.body_text;

attachment.write(current, fileName, contentType, content);

 current.insert();

 

In the below line,

var content = email.content_type + "\n" + email.headers + "\n\n\n\n" + email.body_text;

make sure to add email.body_text not email.body.

If you use email.body you will not able to see the output.

If you use email.body_text you will be able to see the output.

1 ACCEPTED SOLUTION

SSA1
Giga Expert

This is the correct answer. 

In the var content use email.body_text. If you use email.body you will not see the output.

 

  var attachment = new GlideSysAttachment();
   var fileName = email.subject + '.eml';
   var contentType = 'application/octet-stream';
   var content = email.content_type + "\n" + email.headers + "\n\n\n\n" + email.body_text;

   attachment.write(current, fileName, contentType, content);

   current.insert();

View solution in original post

5 REPLIES 5

Did you got anything because i am facing the same issue