Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Reading Emails

Reply
Thread Tools

Reading Emails

 
 
freesoft_2000
Guest
Posts: n/a
 
      07-12-2005
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


 
Reply With Quote
 
 
 
 
Alan Krueger
Guest
Posts: n/a
 
      07-13-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
READING EMAILS Savas Ates ASP .Net 13 01-31-2006 02:59 AM
Scanning my emails for harmfull emails etc lee.ingram Computer Support 4 01-12-2006 01:21 AM
Reading emails Jeff VanBeekum Computer Support 1 12-25-2004 07:49 PM
How to stop Sir name showing on emails from hotmail emails Drifter Computer Information 3 07-07-2004 07:15 AM



Advertisments