|
|
|
|
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.
|
|

01-03-2008, 07:04 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
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
|
|

01-04-2008, 05:56 AM
|
 |
Member
|
|
Join Date: Dec 2007
Location: Singapore
Posts: 18
|
|
|
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 ?
|
|

01-05-2008, 12:31 AM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
I want to copy a file attached to an email in the outlook inbox to the Java application.
|
|

01-05-2008, 12:49 AM
|
 |
Moderator
|
|
Join Date: Jan 2008
Location: Dallas
Posts: 260
|
|
|
Copying ?? i am still confused .. do you want to read file attached in email ?
__________________
dont worry newbie, we got you covered.
|
|

01-07-2008, 05:55 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
yes, I need to read the file attahced in email. How do read it?
|
|

01-07-2008, 06:41 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 20
|
|
|
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");
|
|

01-07-2008, 06:58 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
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
|
|

01-07-2008, 07:30 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 20
|
|
|
Part and disposition does that ..
Did you try that code
__________________
System.out.println("Logged in as ROOT");
|
|

01-07-2008, 07:33 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 20
|
|
|
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");
|
|

01-07-2008, 07:45 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
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...
|
|

01-07-2008, 07:50 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
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.
|
|

01-07-2008, 09:42 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 20
|
|
|
Yes its possible..
__________________
System.out.println("Logged in as ROOT");
|
|

01-07-2008, 10:04 PM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 7
|
|
|
Please let me know how it can be done or the link where i can find it.
|
|

01-09-2008, 07:51 AM
|
|
Member
|
|
Join Date: Jan 2008
Posts: 20
|
|
|
g4j api for gmail .. you can get the source from SourceForge
__________________
System.out.println("Logged in as ROOT");
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
All times are GMT +3. The time now is 03:50 AM.
|
|
VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org