You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by _d <do...@yahoo.fr> on 2012/03/07 11:24:15 UTC
SMTP: sending file binary as attachment corrupted
Hello,
i need to send a binary file (zip file for example) as an attachment via
email.
when I get the attachment in my mailbox the file is corrupted.
*here is my config *
as you can see, i set the mime type to application/octet-stream.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<endpoint id="ompSMTPEndpoint"
uri="smtp://myhost:25?from=myemail&to=myemail" />
<route>
<from uri="file:C:\work?initialDelay=5000&delay=300000" />
<setHeader headerName="Content-Type">
<simple>application/octet-stream;name="${file:onlyname}";</simple>
</setHeader>
<setHeader headerName="Content-Disposition">
<simple>attachment;filename="${file:onlyname}";size=${file:size}</simple>
</setHeader>
<setHeader headerName="subject">
<simple>Filename ${file:onlyname} date ${date:now:dd/MM/yyyy
HH:mm:ss}</simple>
</setHeader>
<to ref="ompSMTPEndpoint" />
</route>
</camelContext>
</beans>
the mail source code in my mailbox :
Content-Type: application/octet-stream; name="FILENAME.ZIP"
Content-Disposition: attachment;filename="FILENAME.ZIP";size=11191
Content-Transfer-Encoding: base64
/
hope i've been brief and clear, thank you for your help/
--
View this message in context: http://camel.465427.n5.nabble.com/SMTP-sending-file-binary-as-attachment-corrupted-tp5543701p5543701.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: SMTP: sending file binary as attachment corrupted
Posted by _d <do...@yahoo.fr>.
Thanks
it's working fine, with this code
public void process(Exchange ex) throws Exception {
{
String fileNameWritten = (String) ex.getIn().getHeader(
"CamelFilePath", String.class);
String fileName = (String) ex.getIn().getHeader(
Exchange.FILE_NAME_ONLY, String.class);
ex.getIn().setBody(fileName);
ex.getIn().addAttachment(fileName,
new DataHandler((new FileDataSource(fileNameWritten))));
}
--
View this message in context: http://camel.465427.n5.nabble.com/SMTP-sending-file-binary-as-attachment-corrupted-tp5543701p5545931.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: SMTP: sending file binary as attachment corrupted
Posted by ychawla <pr...@yahoo.com>.
Hello,
I remember I had some issues attaching files so I added a processor that
read them directly from the file system. For example:
public void addEmailAttachment(Exchange ex)
{
String fileNameWritten =
(String)ex.getIn().getHeader("CamelFileNameProduced");
ex.getIn().addAttachment("filename.zip", new DataHandler(new
FileDataSource(fileNameWritten)));
}
The Camel Header: CamelFileNameProduced is the actual path to the file on
the file system.
Thanks,
Yogesh
--
View this message in context: http://camel.465427.n5.nabble.com/SMTP-sending-file-binary-as-attachment-corrupted-tp5543701p5544370.html
Sent from the Camel - Users mailing list archive at Nabble.com.