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);
msg.addHeader("CONTENT-TYPE","multipart/mixed");
Transport tr = session.getTransport("smtp");
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.addHeader("CONTENT-TYPE","text/plain");
mbp1.setText("hello world");
FileDataSource fds = new FileDataSource(somefilename);
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.addHeader("CONTENT-TYPE","application/octet-stream");
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
Multipart mp = new MimeMultipart();
int index = 0;
mp.addBodyPart(mbp1,index++);
mp.addBodyPart(mbp2,index++);
msg.setContent(mp);
tr.sendMessage(msg,msg.getAllRecipients());
tr.close();
Thanks!