cancel
Showing results for 
Search instead for 
Did you mean: 

Attachment in Mail Receiver Adapter

Former Member
0 Kudos

Hi,

I wrote a Adapter Module to create attachment in Receiver Mail Adapter. I create a PDF document using the IText API and create the attachment using this one. But it not work properly and the attachment is not send with the e-mail. My code is:

public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData)

throws ModuleException{

try{

Document doc = new Document(PageSize.A4);

ByteArrayOutputStream out = new ByteArrayOutputStream();

PdfWriter.getInstance(doc,out);

doc.open();

PdfPTable table = new PdfPTable(3);

PdfPCell cell;

cell = new PdfPCell(new Paragraph("Rank"));

cell.setBackgroundColor(new Color(34, 90, 141));

table.addCell(cell);

cell = new PdfPCell(new Paragraph("Name"));

cell.setBackgroundColor(new Color(34, 90, 141));

table.addCell(cell);

cell = new PdfPCell(new Paragraph("Points"));

cell.setBackgroundColor(new Color(34, 90, 141));

table.addCell(cell);

//add the data rows.

int flag = 0;

Color bg;

for (int i = 0; i <= 10; i++){

//alternate colors

if (flag == 0){

flag = 1;

bg = new Color(204, 204, 255);

} else {

flag = 0;

bg = new Color(255, 255, 255);

}

cell = new PdfPCell(new Paragraph("1"));

cell.setBackgroundColor(bg);

table.addCell(cell);

cell = new PdfPCell(new Paragraph("Prakash Singh: " + i));

cell.setBackgroundColor(bg);

table.addCell(cell);

cell = new PdfPCell(new Paragraph("" + (50000 - i * 10) + ""));

cell.setBackgroundColor(bg);

table.addCell(cell);

}

doc.add(table);

doc.close();

Message msg = (Message)inputModuleData.getPrincipalData();

AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(),AuditDirection.INBOUND);

Audit.addAuditLogEntry(amk,AuditLogStatus.SUCCESS,"CreateAttachment: Module Called");

Payload attachment = msg.createPayload();

attachment.setName("Order");

attachment.setContentType("Plain/Text");

attachment.setContent(out.toByteArray());

msg.addAttachment(attachment);

inputModuleData.setPrincipalData(msg);

}catch (Exception ex){

ModuleException me = new ModuleException(ex);

throw me;

}

return inputModuleData;

}

somebody has some ideia.

thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

In the Module which u have developed set the content type to "application/pdf". It will change the content type.

With Regards

K.Varadharajan

Award points if it is usefull

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks. I set the contentType with Application/pdf and it work fine.

Former Member
0 Kudos

Hi,

I checked the "Keep Attachments" in the Communication Channel and the file was sent, but the extension of attachment is .bin. How I do to change the extension file name in attachment to .pdf? And how I do to keep the content in body of the mail when the keep attachments is checked?

thanks.

moorthy
Active Contributor
0 Kudos

Hi,

following links may help u:

/people/sravya.talanki2/blog/2006/11/28/e-mail-xml-messages-in-pdf-format-from-sap-xi

/people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure

Hope this helps,

rgds,

Moorthy

Former Member
0 Kudos

hey

u can use the File to mail(bypass scenario) for this.

don't do anything in IR,just do the configuration in ID and send the mail.

have a look at the following for bypass scenario

/people/william.li/blog/2006/09/08/how-to-send-any-data-even-binary-through-xi-without-using-the-integration-repository

thanx

ahamd

Former Member
0 Kudos

In my scenario, I don't have a PDF file... I need to build the PDF file with the XML content in payload and send the PDF document as an attachment in an e-mail.

thanks.