cancel
Showing results for 
Search instead for 
Did you mean: 

file to mail

Former Member
0 Kudos

Hi All,

sorry for posting this again, but i haven't found the answer......

I am doing File(FTP) to mail Scenario. i am picking up the flat file from the Source directory using FTP server.For this we dont need any IR Objects. Receiver side i am using mail adapter.I am able to receive the mail. But it is coming as a .xml attachment. I want the payload as Body of the mail...... or atleast as .txt attachment.

I am using the mail adapter without mail package

If i have to use mail package, then how to do it, bcz there is no source structure to map with the mail structure as i am picking the flat file using FTP server

Transport Protocol: SMTP

Message Protocol: XIPAYLOAD

Without mail package

I have used Module configuration also but no luck....

I used Message Transform Bean

Transform.ContentType text/plain;chaeset=utf-8

Transform.ContentDisposition inline

Its giving an error like " error in method process, transaction is marked for roll back"

Please help me in getting the Requirment...........

Regards,

Raju

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Raju,

If your are using >= SAP PI7.1 above code will work. If you are using <SAP PI7.1 below code will work. Please take help of your colleague who had already worked with Java Mapping before.

package com.Mail;

import java.io.*;
import com.sap.aii.mapping.api.*;
import java.util.Map;

public class MailPackage_JavaMapping1 implements StreamTransformation {

    private Map map;

    public void setParameter(Map map1) {
    }

    public void execute(InputStream inputstream, OutputStream outputstream) throws StreamTransformationException {
        try {
            //Edit these values
            String Subject = "Enter your Subject here";
            String From = "From@gmail_com";
            String To = "To@gmail_com;To1@gmail_com;To3@gmail_com";

            String Content_Type = "text/plain";
            //Read the input payload, which is flat file
            byte[] b = new byte[inputstream.available()];
            inputstream.read(b);
            String Content = new String(b);

            String outputMailPackage = "";
            outputMailPackage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\"> <Subject>"
                    + Subject + "</Subject>  <From>" + From + "</From> <To>" + To + "</To>  <Reply_To />  <Content_Type>"
                    + Content_Type + "</Content_Type>  <Content>" + Content + "</Content> </ns:Mail>";
            outputstream.write(outputMailPackage.getBytes());
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

Regards,

Raghu_Vamsee

Former Member
0 Kudos

Thanks Vamsee,

I am using PI 7.0 , i will check up with this code........ My friends haven't worked on Java mapping..........

Former Member
0 Kudos

Hi Vamsee,

I am getting the following error in Java mapping. plzz help me in solving this.........

Unable to find resource com/Mail/MailPackage_JavaMapping1.class (http://sap.com/xi/XI/Mail/30, bc431b00-4d92-11db-b30c-f488ac130c39, -1)

 

Thanks @ Regards,

Raju.

Former Member
0 Kudos

Hi Raghu,

Thank you very much for ur help. I solved my problem.....

Mai i know your personal email......

Regards,

Raju.D

0 Kudos

Hi raju i have the Same requirement instead of posting in sdn will u give your id so that i can contact

Regards

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi,

you can get a .txt with coma separated values in it by using these modules.

1 localejbs/AF_Modules/StrictXml2PlainBean Local Enterprise Bean strict2plain

2 localejbs/AF_Modules/MessageTransformBean Local Enterprise Bean contentType

5 sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean Local Enterprise Bean mail

contentType Transform.ContentDispostion : attachment;

contentType Transform.ContentType : text/plain;charset="UTF-8";name="Attachment.csv/txt"

contentType Transform.Description : file

strict2plain DataRecord.endSeparator : \r\n

strict2plain DataRecord.fieldSeparator : ,

strict2plain fieldNames : "list of fields"

strict2plain recordTypes : DataRecord

Regards

Aravind

Former Member
0 Kudos

Thanks Aravind for quick response.... but its not working.......

Former Member
0 Kudos

Hi,

Try referring to this post:

Regards,

Aravind

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Raju,

Please check this thread [Link|;

I request you to close this thread, if your issue is solved.

Regards,

Raghu_Vamsee

Former Member
0 Kudos

Hi Vamsee,

the code you suggested is not compiling..... its giving some errors.......... may be the Classes

AbstractTransformation

TransformationInput

TransformationOutput are not there in the XI server....... can you please suggest some different code.........

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

RaghuVamseedhar
Active Contributor
0 Kudos
package com.Mail;

import java.io.InputStream;
import java.io.OutputStream;

import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;

public class MailPackage_JavaMapping extends AbstractTransformation {

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
        try {
            //Edit these values
            String Subject = "Enter your Subject here";
            String From = "From@gmail_com";
            String To = "To@gmail_com;To1@gmail_com;To3@gmail_com";

            String Content_Type = "text/plain";

            //Read the input payload, which is flat file
            InputStream inputstream = transformationInput.getInputPayload().getInputStream();
            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
            byte[] b = new byte[inputstream.available()];
            inputstream.read(b);
            String Content = new String(b);

            //Constructing the XML message <a href="http://help.sap.com/saphelp_nwpi711/helpdata/en/6b/4493404f673028e10000000a1550b0/frameset.htm" TARGET="test_blank">http://help.sap.com/saphelp_nwpi711/helpdata/en/6b/4493404f673028e10000000a1550b0/frameset.htm</a>
            String outputMailPackage = "";
            outputMailPackage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\"> <Subject>"
                    + Subject + "</Subject>  <From>" + From + "</From> <To>" + To + "</To>  <Reply_To />  <Content_Type>"
                    + Content_Type + "</Content_Type>  <Content>" + Content + "</Content> </ns:Mail>";

            outputstream.write(outputMailPackage.getBytes());

        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}
Former Member
0 Kudos

thanks very much raghu for your guidance......

sorry for giving late reply.....i am in vacation till today.........

can u please suggest me how to do java mapping............

RaghuVamseedhar
Active Contributor
0 Kudos

Hi raju.danthuluri,

MessageTransformBean http://help.sap.com/saphelp_nwpi711/helpdata/en/57/0b2c4142aef623e10000000a155106/frameset.htm should work. But I do not know why it is not working. Give it a try with some more possible combinations.

Now that MessageTransformBean is not working. Letu2019s go with u201CUse Mail Packageu201D option in receive mail channel. As you know, to use u201CUse Mail Packageu201D, the payload which is going to Receiver channel should look like this, http://help.sap.com/saphelp_nwpi711/helpdata/en/6b/4493404f673028e10000000a1550b0/frameset.htm

<?xml version="1.0" encoding="UTF-8"?>
 
<ns:Mail xmlns:ns="http://sap.com/xi/XI/Mail/30">
  <Subject>Subject</Subject>
  <From>namea@company_com</From>
  <To>nameb@company_com</To>
  <Reply_To />
  <Content_Type>text/plain</Content_Type>
  <Content>
This is the content.
  </Content>
</ns:Mail>

Now you have to use ESR objects. We cannot use Graphical, XSLT mapping as input in this case is not XML (it is flat file). So, letu2019s go with Java Mapping (help - ).

Step 1: Import XSD and this XSD is for input and output structures (SAP Note 748024: Here you can download the XSD structure of the Mail Package) (Note: You can use some dummy DT and MT).

Step 2: Create Sender and Receiver Message Interfaces using imported XSD.

Step 3: Create an Operational mapping using above Message Interfaces (Step 2).

Step 4: Create a Java Mapping, using below code. Use this Java Mapping in Operational mapping.

Step 5: In Receiver Mail channel select u201CUse Mail Packageu201D.

Step 6: Test the interface, in SXI_MONITOR, payload should look same as above XML.

Regards,

Raghu_Vamsee

Edited by: Raghu Vamsee on Jan 9, 2011 1:56 AM

Former Member
0 Kudos

I already used MessageTransformBean

I have mentioned the parameters that i have used in my post..

please see and let me know it is correct or not.......

stefan_grube
Active Contributor
0 Kudos

what is the error message?

Former Member
0 Kudos

the error is.....

Delivery of the message to the application using connection Mail_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.ms.api.RecoverableException: Exception thrown in method process. The transaction is marked for rollback.: com.sap.engine.services.ejb.exceptions.BaseTransactionRolledbackLocalException: Exception thrown in method process. The transaction is marked for rollback..

stefan_grube
Active Contributor
0 Kudos

And without MTB it works? that is strange.

maybe your encoding is not UTF-8?

Transform.ContentType text/plain;chaeset=utf-8

It should be: charset

you could try: Transform.ContentType text/plain;charset=ISO8859-1

Former Member
0 Kudos

Soory i have made a Typo error.......

i have used charset=utf-8 only........

i have used both, but no luck......

can u suggest any other solution..........

Former Member
0 Kudos

Please anybody help me............

Former Member
0 Kudos

Thanks for your quick reply

I already followed the guide, but can we do without mail package.

if mail package is compulsary, then how to map the mail structure with source flat file

stefan_grube
Active Contributor
0 Kudos

You can do this with Java mapping only.

But it should work without Mail Package. Just use MessageTransformBean.

stefan_grube
Active Contributor
0 Kudos