File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes problem with java mail attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem with java mail attachment" Watch "problem with java mail attachment" New topic

problem with java mail attachment

peter qiu

Joined: Dec 10, 2002
Posts: 4
i used java mail api to program email sending. Now i have the problem that the attachment could not be treated as the independent attached file but displayed following the main text as the meanless characters, no matter what type of attachment i include, zip, au files. The main codes are:
Session session = Session.getDefaultInstance(props, null);
MimeMessage msg = new MimeMessage(session);
Transport tr = session.getTransport("smtp");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText("hello world");
FileDataSource fds = new FileDataSource(somefilename);
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setDataHandler(new DataHandler(fds));
Multipart mp = new MimeMultipart();
int index = 0;
peter qiu

Joined: Dec 10, 2002
Posts: 4
if i use "Transport.send(msg);" instead of "tr.sendMessage(msg,msg.getAllRecipients());", the attachment file shows ok, but the authentication process which must use a Transport instance can't be done properly. How can i resolve this conflict?
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
I do not really know where the problem could be, but have a look at my approach:

There is no need to set the CONTENT-TYPE manually.
Hope it helps
I agree. Here's the link:
subject: problem with java mail attachment
It's not a secret anymore!