Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-03-2008, 08:04 PM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
copying file from a email/word to a Java application
Hi,

I have a requirement to copy a file in a email or a word document to a java application. Using system clipboard i can copy a file in a hard drive location in a PC to the Java application, but i am not able to copy a file from an email to java application.

Please provide some inputs if you have any idea regarding this.

Regards,
cmbl
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-04-2008, 06:56 AM
simi's Avatar
Member
 
Join Date: Dec 2007
Location: Singapore
Posts: 18
simi is on a distinguished road
Send a message via Yahoo to simi
do you want to attach file to an email using javamail api ? or do you want to copy file attached to an email from your outlook inbox ?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 01:31 AM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
I want to copy a file attached to an email in the outlook inbox to the Java application.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 01:49 AM
roots's Avatar
Moderator
 
Join Date: Jan 2008
Location: Dallas
Posts: 263
roots is on a distinguished road
Copying ?? i am still confused .. do you want to read file attached in email ?
__________________
dont worry newbie, we got you covered.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-07-2008, 06:55 PM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
yes, I need to read the file attahced in email. How do read it?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-07-2008, 07:41 PM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
ultipart mp = (Multipart)(message[0].getContent());

// Displays Inbox
for (int i=0; i < message.length; i++) {
System.out.println(i + ": " + message[i].getFrom()[0]
+ "\t" + message[i].getSubject());}

for (int i=0, n=mp.getCount(); i<n; i++) {

Part part = mp.getBodyPart(i);
String disposition = part.getDisposition();

if ((disposition != null) &&
(disposition.equals(Part.ATTACHMENT) ||
(disposition.equals(Part.INLINE)))) {

// Save Attachment
File attachFile = new File(part.getFileName());
for (int j=0; file.exists(); j++) {
attachFile = new File(part.getFileName()+j);}

ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(attachFile));

out.writeObject(part.getInputStream());
out.close();


}

}
__________________
System.out.println("Logged in as ROOT");
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-07-2008, 07:58 PM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
thanks.

The above code gets all the emails in the mail box. But what i need is, i need to read the attachment of the mail which i have opened into the java application.
For this i was taking a different approach of using a Clipboard, because when we do CTRL+C on a file attachment in a email, the attachment is copied to the clipboard as bytes. I need to know how to read the contents in the System clipboard which are in bytes. We need to define a DataFlavor to read bytes from System Clipboard.


Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.getData(DataFlavor.StringFlavor);

A string flavor means any data as strings are retrieved. What i need to get is the data which is in bytes.

Hope u r clear with the
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 01-07-2008, 08:30 PM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
Part and disposition does that ..
Did you try that code
__________________
System.out.println("Logged in as ROOT");
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 01-07-2008, 08:33 PM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
One more thing, I was not clear on what you mean by " i need to read the attachment of the mail which i have opened into the java application.
" Please clarify.
__________________
System.out.println("Logged in as ROOT");
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 01-07-2008, 08:45 PM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
What i meant was, when a mail is opened and it has an attachment. what i do is CTRL+C the attachment. this gets copied as bytes to the clipboard. I need to read the file which is in bytes in Clipboard. Hope it's clear now...
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 01-07-2008, 08:50 PM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
In the above code to get the Messages, do i need to provide the authentication info to connect to the mail server. or is it possible to get the messages from the mail server and user info available on the pc. I would like to know is it possible to set up connection to the mail box available on a user pc.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 01-07-2008, 10:42 PM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
Yes its possible..
__________________
System.out.println("Logged in as ROOT");
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 01-07-2008, 11:04 PM
Member
 
Join Date: Jan 2008
Posts: 7
cmbl is on a distinguished road
Please let me know how it can be done or the link where i can find it.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 01-09-2008, 08:51 AM
Member
 
Join Date: Jan 2008
Posts: 20
maruthi_s is on a distinguished road
g4j api for gmail .. you can get the source from SourceForge
__________________
System.out.println("Logged in as ROOT");
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Live Email Validation In Java shameel Web Frameworks 7 10-08-2008 02:40 PM
Java Email Server 1.6 JavaBean Java Announcements 0 11-21-2007 10:00 PM
Copying Arrays JavaForums Java Blogs 0 11-04-2007 12:11 AM
Access Email usind a java mail client Access Email usind a java mail client consult4u Enterprise JavaBeans 2 07-31-2007 10:29 AM
How to update Existing Word Doc Using java umashankar Advanced Java 1 07-27-2007 03:29 PM


All times are GMT +3. The time now is 11:29 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org