File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes email attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "email attachment" Watch "email attachment" New topic
Author

email attachment

Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
i need to has a email function, but how can i store the attachment path
and then retrieve to let user click to download
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Please check your Private Messages.


[My Blog]
All roads lead to JavaRanch
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

Assuming you are using POP3 or IMAP to access the email from the server...

Both the protocols allow you to access a message and all its attachments easily, is your problem reading the message?

provide some more details ....


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
yes. if i store the attachment path
how can i read it and add hyerlink let user download like common email function
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

I dont think you can add that as an hyperlink in your application.
mail servers would usually not have a static address for the attachments.

The attachment will be available to your application only when the user has successfully authenticated with the email server and your application has queried for the details of a selected email.

The attachment received will be a part of the Message object.

lets hope this helps you get started, i have left out the attachments part for you...

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Part.getContent() is your friend when reading anything from an email's contents. Message implements Part.

Run the following recursive call on your Message and see what it returns:
You'll then see for each little part of your email how it is represented. The content could be a String, Multipart, or something else. It's one of those "something else"s you will need.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
my code is as below:

MultipartRequest multi = new MultipartRequest(httpRequest , "." , 5*1024*1024 , "big5");

String mailserver = "smtpo.hkbn.net";
String From = multi.getParameter("From");
String to = multi.getParameter("To");
String Subject = multi.getParameter("Subject");
String type = multi.getParameter("Type");
String messageText = multi.getParameter("Message");
String FileName = multi.getFilesystemName("FileName");

boolean sessionDebug = false;

try {


java.util.Properties props = System.getProperties();

props.put("mail.host",mailserver);
props.put("mail.transport.protocol","smtp");


....this is part of my code....

do i insert email attachment as string object into the database.
and treat as string object to select attachment to resultset
how to add link to text,after clicking text ,then download and save as the attachement.???
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Please UseCodeTags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

I have one important question: what do you want to do exactly? Read an attachment from an existing email, add an attachment to a new email, something else? Because it's not completely clear to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: email attachment
 
Similar Threads
Need a code forward an email with an attachment
Java Mail attachment Scanning
Compatibility
saving attachements from a mail
unable to view email attachments!!!!