Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Got empty attachment when sending email using JavaMail Multipart

843830Dec 5 2006 — edited Dec 6 2006
I have problem sending an email using JavaMail Multipart. Here is the piece of code:

Multipart mp = new MimeMultipart();
// create and fill the first message part - email content
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText("email content");
mp.addBodyPart(mbp1);

// create the second message part - an attachment
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource("C:/file.txt");
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);

// add the Multipart to the message
msg.setContent(mp);
Transport.send(msg);

The email gets send successfully. However, the email content is not seen and the attachment is empty.

I have turned on the javamail debug, there only one part and nothing is displayed in that part. Following is what I got from debug:

==============================================
.....
354 End data with <CR><LF>.<CR><LF>
Message-ID: <3577952.1165299176687.JavaMail.javamailuser@localhost>
From: John Doe <jdoe@gmail.com>
To: Someone <someone@yahoo.com>
Subject: Email Test
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_0_2388206.1165299176593"


.
250 Ok: queued as C5BB7A743

==================================================

If I write an standalong application (one JSP and this Java class), it works fine. I can see my email content and my attachment. However, when I plug in to my application, the email content and attachment are messed up. I cannot figure out which setting causes this problem. Any thought will be appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2007
Added on Dec 5 2006
4 comments
1,473 views