Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to attach a TextFile as a File?

 
Axel Foley
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I want to attach a Textfile to a Email and it works but the text is displayed in the Bodypart itself.
But I want it to be an attachment and not a part of the body!
How can I do that?
*Axel*
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "corsa12". Welcome to JavaRanch!
Please change your name to comply with the naming policy to which you agreed when you registered here..

For your publicly displayed name,
use a first name, a space, and a last name.

You can change your name:
here

You can also find the naming policy:
here
Thank You!
 
Ankur Goyal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call the setDisposition(PART.ATTACHMENT) method on the body part
 
Axel Foley
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do this, but the file is still coming in the body part and not as an attachment... :
...
MimeBodyPart mbp2 = new MimeBodyPart();
FileDataSource fds = new FileDataSource(pFile);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(pFile);
// create the Multipart and its parts to it
Multipart mp = new MimeMultipart();
mbp2.setDisposition(Part.ATTACHMENT);
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
msg.setContent(mp);
...
whats wrong with that code?
*A*
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic