This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
HOW DO I SEND A ATTACHMENT & MESSAGE BOTH TOGETHER USIN JAVAMAIL
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Originally posted by saheli sen gupta: HOW DO I SEND A ATTACHMENT & MESSAGE BOTH TOGETHER USIN JAVAMAIL
hi saheli using multipart class of javamail api you can send both message and attachment together.go through the following code it will give u some idea about message and attachment. Session session = Session.getDefaultInstance(props, null); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(mailFrom)); InternetAddress[] address = {new InternetAddress(mailTo)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject(subject); msg.setSentDate(new Date()); // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(message); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(fileName); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message msg.setContent(mp); // set the Date: header msg.setSentDate(new Date());
// send the message Transport.send(msg);
saheli sen gupta
Greenhorn
Joined: Nov 03, 2000
Posts: 13
posted
0
Thanks , I have already tried out in the stated approach.Problem was I coudn't get the the file as a attachment( content is diplayed properly) along with that the boundary is also diaplayed.
KASI VISHWANATH
Ranch Hand
Joined: Aug 06, 2000
Posts: 60
posted
0
see the examples given along with the java mail application ------------------ I.K.VISHWANATH