This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes How to send email with no attachment? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to send email with no attachment?" Watch "How to send email with no attachment?" New topic
Author

How to send email with no attachment?

Alvin de Jesus
Greenhorn

Joined: May 05, 2001
Posts: 3
MimeBodyPart textPart = new MimeBodyPart();
textPart.setText(text);

I've written a email servlet using Java Mail that allows file attachment.
The problem that I'm having is that every time I send an email without a attach file. The email does not sends out.
Please advise! Alvin
Here's my code looks like:
======================================
Multipart mp = new MimeMultipart();

MimeBodyPart attachFilePart = new MimeBodyPart();

FileDataSource fds = new FileDataSource(attachment);
attachFilePart.setDataHandler(new DataHandler(fds));
attachFilePart.setFileName(fds.getName());

mp.addBodyPart(textPart);
mp.addBodyPart(attachFilePart);
message.setContent(mp);
 
jQuery in Action, 2nd edition
 
subject: How to send email with no attachment?