944,179 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3301
  • Java RSS
Jul 12th, 2005
0

Reading Mail

Expand Post »
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

Java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: scrollbar applet
Next Thread in Java Forum Timeline: Connecting to Oracle through Blackberry Handheld Device





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC