cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Mail-Adapter attachment with specified name

thorsten_hautz
Participant
0 Kudos

Hi,

We have the following scenario:

We have some EDIFACT-suppliers which we have to connect over Mail-adapter.

We have to fullfill several specifications by sending the mail.

So we have to create a specific filename for the EDI-attachment and the subject. Therefore I used the adapterspecific attribute THeaderSUBJECT, which we set in Mapping. This works fine.

Now the problem: We have to send only the payload-document as attachment of the mail with the same name as the subject of the mail. So we can't use the keep-attachment flag because then all attachments of this message would be sent in the mail.

How is it possible to send only the payload as attachment without any other documents and with specified filename in the attribute THeaderSUBJECT?

Has anybody an idea how to solve this problem?

Regards

Thorsten

Accepted Solutions (0)

Answers (2)

Answers (2)

thorsten_hautz
Participant
0 Kudos

Hi,

I have found a solution.

In a new module I copy the original paload to the payload of a new message object without attachments.

After calling this module I call the standard module MessageTransformBean to transform the payload into the attachment of the message.

Here the code of my module:


String fileName = msg.getMessageProperty("http://sap.com/xi/XI/System/Mail","THeaderSUBJECT");

// Generate new message object
Context ctx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ctx.lookup(com.sap.aii.af.ra.ms.api.ConnectionFactory.JNDI_NAME);
MessageFactory factory = cf.createMessageFactory("XI");
Message msgnew = factory.createMessage(msg.getFromParty(),msg.getToParty(),msg.getFromService(),msg.getToService(), msg.getAction());
msgnew.setConversationId(msg.getConversationId());
msgnew.setDeliverySemantics(msg.getDeliverySemantics());
msgnew.setCorrelationId(msg.getMessageId());
msgnew.setMessageProperty("http://sap.com/xi/XI/System/Mail","THeaderSUBJECT",fileName);
			
			
String contentType = new String("text/plain;name="" + fileName + """);			
			
// Copy original message to the new message
XMLPayload payload = (XMLPayload)(msg.getDocument());
payload.setContentType(contentType);
payload.setDescription("file");
payload.setName(fileName);
			
msgnew.setDocument(payload);

Now it works like it should work.

Regards

Thorsten

Former Member
0 Kudos

Hi Thorsten,

Happy to see that you solved your problem.

Regards,

Hui

Former Member
0 Kudos

Hi Thorsten,

With MessageTransformBean you can change your payload to attachment and set the name of the attachment.

Parameter Value

Transform.ContentDisposition attachment;filename=”abc.txt”

But your problem is that the name of the attachment is not fixed but should be retrieved from adapter specific message header THeaderSUBJECT.

So I don't see any possibility to use the existing configuration or modules to solve your problem. Maybe you have to develop a module to set the name of the attachment.

I'm also interested to know whether others have any ideas.

Regards,

Hui