on 08-19-2008 11:11 AM
Hi,
I have scenario from ABAP Proxy with attachment to Mail. The problem is i cannot send mail both mail content and file attachment.
Because when i tick the "keep attachment" in the mail adapter so both content and attachment become attachment, but if i didn't tick, only mail content is display by the recipient without the attachment.
How can i configure mail adapter so the recipient can receive both mail content and attachment.
Thank you and best regards
fernand
Hi William,
Yes, i have resolved the problem already, The workaround is to using module in mail adapter. You can see my code, but you need to modify little bit for your case. Don't tick "keep attachment" in the mail adapter cc.
/*
Created on Aug 22, 2008
*
To change the template for this generated file go to
Window>Preferences>Java>Code Generation>Code and Comments
*/
package zmail;
/**
@author Fernand Lesmana
August 2008
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
*/
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import com.sap.aii.af.mp.module.*;
import com.sap.aii.af.ra.ms.api.*;
import com.sap.aii.af.service.auditlog.*;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import it.sauronsoftware.base64.*;
/**
@ejbHome <{com.sap.aii.af.mp.module.ModuleHome}>
@ejbLocal <{com.sap.aii.af.mp.module.ModuleLocal}>
@ejbLocalHome <{com.sap.aii.af.mp.module.ModuleLocalHome}>
@ejbRemote <{com.sap.aii.af.mp.module.ModuleRemote}>
@stateless
*/
public class CreateAttachment implements SessionBean, Module {
private SessionContext myContext;
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext context) {
myContext = context;
}
public void ejbCreate() throws CreateException {
}
public static String getNodeValue(Node node) {
StringBuffer buf = new StringBuffer();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node textChild = children.item(i);
if (textChild.getNodeType() != Node.TEXT_NODE) {
System.err.println("Mixed content! Skipping child element " + textChild.getNodeName());
continue;
}
buf.append(textChild.getNodeValue());
}
return buf.toString();
}
protected static int copySource(InputStream in, OutputStream out)
throws IOException {
Base64OutputStream encoder = new Base64OutputStream(out);
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int count = 0;
int n = 0;
while (-1 != (n = in.read(buffer))) {
encoder.write(buffer, 0, n);
count += n;
}
return count;
}
public ModuleData process(
ModuleContext moduleContext,
ModuleData inputModuleData)
throws ModuleException {
String subject = null;
String to = null;
String from = null;
String content = null;
String isAttachment = null;
String attachmentName = null;
String fileName = null;
String mimeType = null;
AuditMessageKey amk = null;
String boundary = "--AaZz";
String CRLF = "\r\n";
int fileSize = 0;
try {
Message msg = (Message) inputModuleData.getPrincipalData();
ByteArrayInputStream bais = new ByteArrayInputStream(msg.getDocument().getContent());
amk = new AuditMessageKey(msg.getMessageId(), AuditDirection.INBOUND);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Reading main payload started.");
// Create a DOM parser
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
// Parse input to create document tree
Document doc = builder.parse(bais);
Node MAINNODE = doc.getFirstChild();
NodeList children = MAINNODE.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node node = children.item(i);
if ("Subject".equals(node.getNodeName())) {
subject = getNodeValue(node);
}
if ("To".equals(node.getNodeName())) {
to = getNodeValue(node);
}
if ("From".equals(node.getNodeName())) {
from = getNodeValue(node);
}
if ("Content".equals(node.getNodeName())) {
content = getNodeValue(node);
}
if ("isAttachment".equals(node.getNodeName())) {
isAttachment = getNodeValue(node);
}
if ("AttachmentName".equals(node.getNodeName())) {
attachmentName = getNodeValue(node);
}
if ("Filename".equals(node.getNodeName())) {
fileName = getNodeValue(node);
}
if ("MimeType".equals(node.getNodeName())) {
mimeType = getNodeValue(node);
}
}
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Reading main payload ended.");
ByteArrayOutputStream baos = null;
baos = new ByteArrayOutputStream();
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Build Mail Package started.");
// create XML structure of mail package
String output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
+ "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"
+ "<Subject>" + subject + "</Subject>"
+ "<From>" + from + "</From>"
+ "<To>" + to + "</To>"
+ "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"
+ "<Content>";
baos.write(output.getBytes());
if (isAttachment.equals("TRUE")) {
// create the declaration of the MIME parts
//First part
output = "--" + boundary + CRLF
+ "Content-Type: text/plain; charset=ISO-8859-1" + CRLF
+ "Content-Transfer-Encoding: 8bit" + CRLF
+ "Content-Disposition: inline" + CRLF + CRLF
+ content + CRLF
//Second part
+ "--" + boundary + CRLF
+ "Content-Type: " + mimeType + "; name=" + fileName + CRLF
+ "Content-Transfer-Encoding: base64" + CRLF
+ "Content-Disposition: attachment; filename=" + fileName + CRLF + CRLF;
baos.write(output.getBytes());
//Source is taken as attachment
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Encode (base64) attachment started.");
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Attachment Name = " + attachmentName);
ByteArrayInputStream bain = new ByteArrayInputStream(msg.getAttachment(attachmentName).getContent());
fileSize = copySource(bain, baos);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Encode (base64) attachment ended. File Size " + Integer.toString(fileSize) + " bytes");
} else {
// create the declaration of the MIME parts
//First part
output = "--" + boundary + CRLF
+ "Content-Type: text/plain; charset=ISO-8859-1" + CRLF
+ "Content-Transfer-Encoding: 8bit" + CRLF
+ "Content-Disposition: inline" + CRLF + CRLF
+ content + CRLF;
baos.write(output.getBytes());
}
baos.write("</Content></ns:Mail>".getBytes());
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS, "Build mail package ended.");
msg.getDocument().setContent(baos.toByteArray());
inputModuleData.setPrincipalData(msg);
} catch (Exception e) {
ModuleException me = new ModuleException(e);
throw me;
}
return inputModuleData;
}
}
Let me know if you still have a problem, so far my program running well without problem.
Best Regards
Fernand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Suddhasatta,
The ex Cape Town man?
No Suddha your solution did not work. Still getting two attachments and no body.
Any other ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fernand ,
Did you ever got this question of yours resolved? If yes please can you expain to me how you did it. I want to achieve exactly the same.
Regards
Willie Hugo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Willie,
Please follow the following steps if you want to send a mail from XI mail adapter with a body and attachments.
For this, your XI message need to have additional attachements to it, which should be sent by the Sender system. Each of these additional XI payloads (XI attachments) will then become an attachment for the mail.
To set these additional XI payloads as attachments,
Check the Keep Attachments check box in the Receiver Mail Adapter Channel.
Now, the main payload of the XI message is by default sent as an attachment of the mail, whether you check the Keep Attachments option or not. To send the main XI attachment as the body of the mail do the following:
1. Go to the "Modules" tab of the receiver mail channel.
2. In the processing sequence area of this tab specify the localejbs/AF_Modules/MessageTransformBean as the first module. Type: Local Enterprise Bean; Module Key: <any_name>
Then in the Module Configuration area enter the following module parameters,
Module Key: <any_name>
Parameter Name: Transform.ContentDisposition
Parameter Value: inline
Module Key: <any_name>
Parameter Name: Transform.ContentDescription
Parameter Value: <any_description>
Module Key: <any_name>
Parameter Name: Transform.ContentType
Parameter Value: text/plain
Be careful while entering the module names and values, do not put any spaces at the end.
Hope this helps.
Regards,
Suddhasatta
Edited by: Suddhasatta Guha on Oct 23, 2008 7:28 AM
Hi,
I already using MessageTransformBean as the first module and set its module parameter "Transform.ContentDisposition" as "inline" but then both payload still become attachment.
i want to make the MainDocument = body and the attachment still remain as attachment.
Please advise.
Best Regards
Fernand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
please refer this link..hope it clarifies ur doubt.
http://help.sap.com/saphelp_nw04/helpdata/en/57/0b2c4142aef623e10000000a155106/content.htm
regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
Below links will help u
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1685 [original link is broken] [original link is broken] [original link is broken]
/people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In Mail adapter u need give
Message protocol as "XIALL"
Regards,
Jayasimha Jangam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fernand,
The mail adapter sends the XI payload as an attachment by default. Checking the option "Keep Attachment", sends additional attachment to the XI message as Mail Attachments. For each
additional payload of the XI message, the mail adapter creates an attachment for the
mail; when you select "Keep Attachment".
Although by default, the main payload of the message is also sent as an attachment, if you want to send the payload as Content (Body) of the mail............in module configuration use MessageTransformBean as the first module and set its module parameter "Transform.ContentDisposition" as "inline" (to keep it as attachment you can set the value as "attachment" as well).
You can also use Mail package in message mapping to set the message content in the mapping.
Hope this helps.
Regards,
Suddha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ur message protocol option is correct. Check this for various options.
/people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure
Regards,
Prateek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.