I am assuming that, u are retriving the mail from a POP3 id.
The best way I can tell u is to use the java mail API.
Its simple and need a small amount of coding.
Or else use the Perl option .
Also u can write a C-program which can very well give u back the attachment, for which u need to understand the structure of the mail file very clearly. after that iat just some string manipulation .