cancel
Showing results for 
Search instead for 
Did you mean: 

File (nfs) to Mail - additional file attached as .xml (original is .zip)

0 Kudos
269

Hi Gurus,

I am developing a file to mail scenario, where I need to send a .zip file to some mail recipients and have some text in the body.

For this purpose, I am using sender File System adapter (NFS) because I am reading the body text from a .txt located in the same path as the file that needs to be attached so I need to use the Additional File(s) parameter for this purpose.

I am able to read the .txt file and have that string in the body of the mail sent and also read the .zip file but it is being attached as .xml and not as .zip

Here are some details in my channels:

Sender file adapter

  • Source tab is File System (NFS) and Additional File(s) option is enabled
  • Processing tab has processing mode as test and File Type as Binary
  • Advanced tab has enabled the ASMA feature with File Name and File Type checkboxes

Receiver mail adapter

  • General tab is NOT using mail package; I completed the textboxes for "from", "to" and "subject" and content encoding is base64. Keep attachments is enabled.
  • In module tab I am using MessageTransformBean with ContentDisposition as inline and ContentType as text/plain;charset="UTF-8"

The way I developed this interface is with no ESR objects (service interfaces are defined as dummy).

I algo tried using Java Mapping for this purpose (only difference is that in the general tab of the recever mail adapter I defined the "To" and "Subject" as Dummy because I am adding that in my MM code). The code used is next one:

public void transform(TransformationInput input, TransformationOutput output) throws StreamTransformationException {
  InputStream inStream = input.getInputPayload().getInputStream();
  OutputStream outStream = output.getOutputPayload().getOutputStream();
  try {
   // Transfer main payload content from input to output
   byte[] content = getInputStreamBytes(inStream);
   outStream.write(content);
   // Update dynamic configuration attributes
   DynamicConfiguration dynConfig = input.getDynamicConfiguration();
   // (1) Email To
   DynamicConfigurationKey emailToKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Mail", "THeaderTO");
   dynConfig.put(emailToKey, "blabla@blabla.com");
   // (2) Email Subject
   DynamicConfigurationKey subjectKey = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Mail", "THeaderSUBJECT");
   dynConfig.put(subjectKey, "Subject from Java Mapping");
  } catch (Exception e) {
   throw new StreamTransformationException("Exception: " + e.getMessage(), e);
  }
}
private byte[] getInputStreamBytes(InputStream inStream) throws IOException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  byte[] buffer = new byte[8192];
  int read = 0;
  while ((read = inStream.read(buffer, 0, buffer.length)) != -1) {
   baos.write(buffer, 0, read);
  }
  baos.flush();
  return baos.toByteArray();
}

Which also works fine but the result is the same one (attached zip appears as .xml)

I assume this might be something weird but I am not able to find the solution.

Is anyone able to let me know how can I attach the .zip file with the right extension?

Thanks in advanced!

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Pavan,

Thanks for the quick reply.

I already tried using PayloadZipbean module and didn't work but I was able to solve it.

The issue was in the additional file options there is a textbox called "file list" so I put there the extension (.zip) after the filename and my attachment now has the naming convention I was looking for.

Answers (1)

Answers (1)

PavanKumar
Active Contributor
0 Kudos

Hi,

Have you tried using PayloadZipbean module with parameter name as zip.mode and value as zip/ zip one in mail receiver cc.

If my understanding correcting xml file will be actual main payload and name attaching as Maindocument.xml


Regards

Pavan