Guest User

Untitled

a guest
Feb 6th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. class Program
  2. {
  3. static StreamWriter sw = null;
  4. static TcpClient tcpc = null;
  5. static SslStream ssl = null;
  6. static string path;
  7. static StringBuilder sb = new StringBuilder();
  8. static byte[] dummy;
  9. string username = "user";
  10. string password = "pass";
  11.  
  12. static void Main(string[] args)
  13. {
  14. try
  15. {
  16. path = Environment.CurrentDirectory + "\emailresponse.txt";
  17.  
  18. if (System.IO.File.Exists(path))
  19. System.IO.File.Delete(path);
  20.  
  21. using (sw = new System.IO.StreamWriter(System.IO.File.Create(path)))
  22. using (tcpc = new System.Net.Sockets.TcpClient("imap.server.com", 993))
  23. using (ssl = new System.Net.Security.SslStream(tcpc.GetStream()))
  24. {
  25. ssl.AuthenticateAsClient("imap.server.com");
  26. receiveResponse("");
  27. receiveResponse("$ LOGIN " + username + " " + password + "rn");
  28. Console.WriteLine("enter the email number to fetch :");
  29. int number = int.Parse(Console.ReadLine());
  30. receiveResponse("$ FETCH " + number + " body[header]rn");
  31. receiveResponse("$ FETCH " + number + " body[text]rn");
  32. receiveResponse("$ LOGOUTrn");
  33. }
  34. }
  35. catch (Exception ex)
  36. {
  37. Console.WriteLine(ex.ToString());
  38. }
  39. }
  40.  
  41. static void receiveResponse(string command)
  42. {
  43. try
  44. {
  45. if (command != "")
  46. {
  47. if (tcpc.Connected)
  48. {
  49. dummy = Encoding.Default.GetBytes(command);
  50. ssl.Write(dummy, 0, dummy.Length);
  51. }
  52. else
  53. {
  54. throw new ApplicationException("TCP CONNECTION DISCONNECTED");
  55. }
  56. }
  57. ssl.Flush();
  58. byte[] bigBuffer = new byte[1024*18];
  59. int bites = ssl.Read(bigBuffer, 0, bigBuffer.Length);
  60. byte[] buffer = new byte[bites];
  61. Array.Copy(bigBuffer, 0, buffer, 0, bites);
  62. sb.Append(Encoding.Default.GetString(buffer));
  63. sw.WriteLine(sb.ToString());
  64. sb = new StringBuilder();
  65. }
  66. catch (Exception ex)
  67. {
  68. throw new ApplicationException(ex.ToString());
  69. }
  70. }
  71. }
Add Comment
Please, Sign In to add comment