Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static StreamWriter sw = null;
- static TcpClient tcpc = null;
- static SslStream ssl = null;
- static string path;
- static StringBuilder sb = new StringBuilder();
- static byte[] dummy;
- string username = "user";
- string password = "pass";
- static void Main(string[] args)
- {
- try
- {
- path = Environment.CurrentDirectory + "\emailresponse.txt";
- if (System.IO.File.Exists(path))
- System.IO.File.Delete(path);
- using (sw = new System.IO.StreamWriter(System.IO.File.Create(path)))
- using (tcpc = new System.Net.Sockets.TcpClient("imap.server.com", 993))
- using (ssl = new System.Net.Security.SslStream(tcpc.GetStream()))
- {
- ssl.AuthenticateAsClient("imap.server.com");
- receiveResponse("");
- receiveResponse("$ LOGIN " + username + " " + password + "rn");
- Console.WriteLine("enter the email number to fetch :");
- int number = int.Parse(Console.ReadLine());
- receiveResponse("$ FETCH " + number + " body[header]rn");
- receiveResponse("$ FETCH " + number + " body[text]rn");
- receiveResponse("$ LOGOUTrn");
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- }
- }
- static void receiveResponse(string command)
- {
- try
- {
- if (command != "")
- {
- if (tcpc.Connected)
- {
- dummy = Encoding.Default.GetBytes(command);
- ssl.Write(dummy, 0, dummy.Length);
- }
- else
- {
- throw new ApplicationException("TCP CONNECTION DISCONNECTED");
- }
- }
- ssl.Flush();
- byte[] bigBuffer = new byte[1024*18];
- int bites = ssl.Read(bigBuffer, 0, bigBuffer.Length);
- byte[] buffer = new byte[bites];
- Array.Copy(bigBuffer, 0, buffer, 0, bites);
- sb.Append(Encoding.Default.GetString(buffer));
- sw.WriteLine(sb.ToString());
- sb = new StringBuilder();
- }
- catch (Exception ex)
- {
- throw new ApplicationException(ex.ToString());
- }
- }
- }
Add Comment
Please, Sign In to add comment