Reading Mail

Reply

Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Reading Mail

 
0
  #1
Jul 12th, 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

  1.  
  2. import java.net.*;
  3. import java.io.*;
  4.  
  5. public class displayMail {
  6.  
  7. public static void main(String arg[]) {
  8. //
  9. // displayMail [mailServer] [user] [password]
  10. try {
  11. Socket s = new Socket(arg[0], 110);
  12. BufferedReader in = new BufferedReader(
  13. new InputStreamReader(s.getInputStream()));
  14. BufferedWriter out = new BufferedWriter(
  15. new OutputStreamWriter(s.getOutputStream()));
  16. displayMail t = new displayMail();
  17. String msg;
  18. t.loginMail(in, out, arg[1], arg[2]);
  19. int i = t.checkMyMail(in,out);
  20. if (i==0) {
  21. System.out.println("No mail waiting.");
  22. }
  23. else {
  24. for (int j=1; j <= i; j++) {
  25. msg = t.getMail(in, out, j);
  26. System.out.println("*****");
  27. System.out.println(msg);
  28. System.out.println("*****");
  29. }
  30. }
  31. }
  32. catch (Exception e) {
  33. e.printStackTrace();
  34. }
  35. }
  36.  
  37. public String getMail
  38. (BufferedReader in, BufferedWriter out, int i)
  39. throws IOException {
  40. String s = "";
  41. String t = "";
  42. send(out, "RETR "+i);
  43. while (((s = in.readLine()) != null)
  44. &&(!(s.equals("."))))
  45. t += s + "\n";
  46. return t;
  47. }
  48.  
  49.  
  50. private void send(BufferedWriter out, String s) throws IOException {
  51. out.write(s+"\n");
  52. out.flush();
  53. }
  54.  
  55. private String receive(BufferedReader in) throws IOException {
  56. return in.readLine();
  57. }
  58.  
  59. private void loginMail(BufferedReader in, BufferedWriter out,
  60. String user, String pass)
  61. throws IOException {
  62. receive(in);
  63. send(out, "USER " + user);
  64. receive(in);
  65. send(out, "PASS " + pass);
  66. receive(in);
  67. }
  68.  
  69. private int checkMyMail
  70. (BufferedReader in, BufferedWriter out)
  71. throws IOException {
  72. return GetNumberOfMessages(in, out);
  73. }
  74.  
  75.  
  76.  
  77. public int GetNumberOfMessages
  78. (BufferedReader in, BufferedWriter out) throws IOException {
  79. int i = 0;
  80. String s;
  81.  
  82. send(out, "LIST");
  83. receive(in);
  84. while((s = receive(in)) != null) {
  85. if (!(s.equals("."))) { i++; }
  86. else return i;
  87. }
  88. return 0;
  89. }
  90. }

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
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond

Tell me what type of software do you like and what would you pay for it

http://www.daniweb.com/techtalkforums/thread19660.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC