Reading Emails

Discussion in 'Java' started by freesoft_2000, Jul 12, 2005.

  1. Hi everyone,

    I am trying to read emails in from a stmp server without javamail api's
    and i so far have only managed to read the e-mail messages but i can't
    seem to read any attachments that come with it. I am not very sure as to
    how i should separate the message from the attachment. This is what i have
    so far

    import java.net.*;
    import java.io.*;

    public class displayMail {

    public static void main(String arg[]) {
    //
    // displayMail [mailServer] [user] [password]
    try {
    Socket s = new Socket(arg[0], 110);
    BufferedReader in = new BufferedReader(
    new InputStreamReader(s.getInputStream()));
    BufferedWriter out = new BufferedWriter(
    new OutputStreamWriter(s.getOutputStream()));
    displayMail t = new displayMail();
    String msg;
    t.loginMail(in, out, arg[1], arg[2]);
    int i = t.checkMyMail(in,out);
    if (i==0) {
    System.out.println("No mail waiting.");
    }
    else {
    for (int j=1; j <= i; j++) {
    msg = t.getMail(in, out, j);
    System.out.println("*****");
    System.out.println(msg);
    System.out.println("*****");
    }
    }
    }
    catch (Exception e) {
    e.printStackTrace();
    }
    }

    public String getMail
    (BufferedReader in, BufferedWriter out, int i)
    throws IOException {
    String s = "";
    String t = "";
    send(out, "RETR "+i);
    while (((s = in.readLine()) != null)
    &&(!(s.equals("."))))
    t += s + "\n";
    return t;
    }


    private void send(BufferedWriter out, String s) throws IOException {
    out.write(s+"\n");
    out.flush();
    }

    private String receive(BufferedReader in) throws IOException {
    return in.readLine();
    }

    private void loginMail(BufferedReader in, BufferedWriter out,
    String user, String pass)
    throws IOException {
    receive(in);
    send(out, "USER " + user);
    receive(in);
    send(out, "PASS " + pass);
    receive(in);
    }

    private int checkMyMail
    (BufferedReader in, BufferedWriter out)
    throws IOException {
    return GetNumberOfMessages(in, out);
    }



    public int GetNumberOfMessages
    (BufferedReader in, BufferedWriter out) throws IOException {
    int i = 0;
    String s;

    send(out, "LIST");
    receive(in);
    while((s = receive(in)) != null) {
    if (!(s.equals("."))) { i++; }
    else return i;
    }
    return 0;
    }
    }

    What are the necessary things that i need to do or changes to the above
    code in order to read the attachments correctly??

    Some codings would really be helpfull

    Thank You

    Yours Sincerely

    Richard West
     
    freesoft_2000, Jul 12, 2005
    #1
    1. Advertising

  2. freesoft_2000

    Alan Krueger Guest

    freesoft_2000 wrote:
    [snip crude POP3 client]
    > What are the necessary things that i need to do or changes to the above
    > code in order to read the attachments correctly??


    POP3 doesn't know anything about attachments. Attachments to emails are
    part of the data returned when you RETR a message. You'll have to parse
    the MIME structure of the email containing the attachment, assuming a
    more primitive attachment mechanism isn't being used.
     
    Alan Krueger, Jul 13, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shahid Hussain

    How can i Receive Emails from VB.Net

    Shahid Hussain, Nov 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    6,539
    Jay B. Harlow [MVP - Outlook]
    Nov 19, 2003
  2. danpres2k
    Replies:
    3
    Views:
    7,519
    danpres2k
    Aug 25, 2003
  3. Savas Ates

    READING EMAILS

    Savas Ates, Jan 27, 2006, in forum: ASP .Net
    Replies:
    13
    Views:
    3,854
    Steven Nagy
    Jan 31, 2006
  4. Replies:
    2
    Views:
    533
  5. navin

    Reading Oulook emails from ASP

    navin, Sep 8, 2009, in forum: ASP General
    Replies:
    0
    Views:
    717
    navin
    Sep 8, 2009
Loading...

Share This Page