Results 1 to 14 of 14
  1. #1
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default 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

  2. #2
    simi's Avatar
    simi is offline Member
    Join Date
    Dec 2007
    Location
    Singapore
    Posts
    18
    Rep Power
    0

    Default

    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 ?

  3. #3
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    I want to copy a file attached to an email in the outlook inbox to the Java application.

  4. #4
    roots's Avatar
    roots is offline Moderator
    Join Date
    Jan 2008
    Location
    Dallas
    Posts
    293
    Rep Power
    7

    Default

    Copying ?? i am still confused .. do you want to read file attached in email ?
    dont worry newbie, we got you covered.

  5. #5
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    yes, I need to read the file attahced in email. How do read it?

  6. #6
    maruthi_s is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    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");

  7. #7
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    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

  8. #8
    maruthi_s is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    Part and disposition does that ..
    Did you try that code
    System.out.println("Logged in as ROOT");

  9. #9
    maruthi_s is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    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");

  10. #10
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

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

  11. #11
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    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.

  12. #12
    maruthi_s is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    Yes its possible..
    System.out.println("Logged in as ROOT");

  13. #13
    cmbl is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    Please let me know how it can be done or the link where i can find it.

  14. #14
    maruthi_s is offline Member
    Join Date
    Jan 2008
    Posts
    20
    Rep Power
    0

    Default

    g4j api for gmail .. you can get the source from SourceForge
    System.out.println("Logged in as ROOT");

Similar Threads

  1. Live Email Validation In Java
    By shameel in forum Web Frameworks
    Replies: 9
    Last Post: 01-05-2010, 06:42 AM
  2. Java Email Server 1.6
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-21-2007, 09:00 PM
  3. Access Email usind a java mail client Access Email usind a java mail client
    By consult4u in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 07-31-2007, 09:29 AM
  4. How to update Existing Word Doc Using java
    By umashankar in forum Advanced Java
    Replies: 1
    Last Post: 07-27-2007, 02:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •