Skip to Content

Read mail attachment in message mapping using UDF,giving error.

Hello Experts,

I am working on a scenario where PI has to read mail and its attachment and send this data to ECC.

Reading mail content is easy but challenge is while trying to read content of the attachment .

I am referring these posts and

The attachment that I have is an excel file which I am planning to send ECC in a field .Now I expect some problem here since this would require me to first convert the excel into a format which could be set in a string field.At ECC end they would again convert the content back to its earlier form.

Problem as of now is that the whole excel (I even tried text file as an attachment) goes to the target field but it only yeilds some garbage value of size 5 or 7 char ex "5@dskjhjd" that's it .Where as I am expecting it to be too long since it has the whole content of the attachment.

Any help is appreciated.

Code I am using in UDF is below:

String Content = ""; String AttachmentID =""; GlobalContainer globalContainer = container.getGlobalContainer(); InputAttachments inputAttachments = globalContainer.getInputAttachments(); if(inputAttachments.areAttachmentsAvailable()) { Collection<String> CollectionIDs = inputAttachments.getAllContentIds(true); Object[] arrayObj = CollectionIDs.toArray(); int attachmentCount = arrayObj.length; for(int i =0;i<attachmentCount;i++) { AttachmentID = (String)arrayObj[i]; Attachment attachments =inputAttachments.getAttachment(AttachmentID); Content = Content + attachments.getContent().toString(); } }return Content;

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Nov 01, 2016 at 10:14 AM

    Hi Dilip,

    The below statement toString method returns object id not the content because getContent() method returns byte array.

    Content = Content + attachments.getContent().toString(); 

    You need to change the statement to below.

    Content = Content + new String(attachments.getContent());



    Add comment
    10|10000 characters needed characters exceeded