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