Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class smtpclient
  4. {
  5.  
  6. static void readAndShowLine(InputStream in) throws IOExceptio
  7. {
  8. int k = 0;//uchwyt na kod bajtu
  9. while ((k = in.read()) != '\n')//czytanie (lini) do wyst¹pienia znaku koñca wiersza
  10. System.out.print((char)k);
  11. }
  12.  
  13.  
  14. public static void main(String[] argc)
  15. {
  16.  
  17. Base64Coder coder = new Base64Coder();
  18.  
  19. try
  20. {
  21. Socket client = new Socket("poczta.o2.pl", 25);
  22. InputStream in = client.getInputStream();
  23. OutputStream out = client.getOutputStream();
  24. readAndShowLine(in);
  25.  
  26. out.write("HELO Zdzisiek\r\n".getBytes());
  27. readAndShowLine(in);
  28.  
  29. out.write("AUTH LOGIN\r\n".getBytes());//uwierzytelnianie serwera
  30. readAndShowLine(in);
  31.  
  32. out.write((coder.encodeString("twoj_login") + "\r\n").getBytes());
  33. readAndShowLine(in);
  34.  
  35. out.write((coder.encodeString("twoje_haslo") + "\r\n").getBytes());
  36. readAndShowLine(in);
  37.  
  38. out.write("MAIL FROM: <Twoj_login@wp.pl>\r\n".getBytes());
  39. readAndShowLine(in);
  40.  
  41. out.write("RCPT TO: single221@wp.pl>\r\n".getBytes());
  42. readAndShowLine(in);
  43.  
  44. out.write("DATA\r\n".getBytes());
  45. readAndShowLine(in);
  46.  
  47. //W³a�ciwa tre�æ wiadomo�ci
  48. out.write("<b>Hello sd,</b>\r\n".getBytes());
  49. out.write("Howdy!!!.......So how are things with u\r\n".getBytes());
  50. out.write("Just wanted to give u this link....check it out\r\n".getBytes());
  51. out.write("\r\n".getBytes());
  52. out.write("\r\n".getBytes());
  53. out.write("<a href=http://www.yahoo.com>Search Engine</a>\r\n".getBytes());
  54. out.write("\r\n".getBytes());
  55. out.write("Bye for Now\r\n".getBytes());
  56. out.write("<b>Signature</b>\r\n".getBytes());
  57.  
  58.  
  59. out.write(".\r\n".getBytes());//Wa¿ne aby zakoñczyæ znakiem '.'
  60. readAndShowLine(in);
  61.  
  62. out.write("QUIT\r\n".getBytes());
  63. readAndShowLine(in);
  64.  
  65. in.close();
  66. out.close();
  67. client.close();
  68. System.out.println("Closed Connection with Server");
  69.  
  70. }
  71. catch (IOException e)
  72. {
  73. System.out.println("Error in Connecting to Port");
  74. }
  75.  
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement