This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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

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
GeeCON Prague 2014
subject: problem with java mail attachment