Advertisement
Guest User

Untitled

a guest
May 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System.Net.Sockets;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System;
  6.  
  7. namespace TcpPOP3Test {
  8.     public class Program {
  9.  
  10.         public string server = "pop.kahosl.be";
  11.         public string user = "";//mijne username
  12.         public string pass = "";//mijne pass
  13.         public const int POORT = 110;
  14.  
  15.  
  16.         public Program() {
  17.             string str = string.Empty;
  18.             string strTemp = string.Empty;
  19.             using(TcpClient tc = new TcpClient()) {
  20.                 tc.Connect(this.server,POORT);
  21.                 using(NetworkStream nws = tc.GetStream()) {
  22.                     using(StreamReader sr = new StreamReader(nws)) {
  23.                         using(StreamWriter sw = new StreamWriter(nws)) {
  24.                             sw.WriteLine("USER " + user);
  25.                             sw.Flush();
  26.                             sw.WriteLine("PASS " + pass);
  27.                             sw.Flush();
  28.  
  29.  
  30.                             List<string> bericht = new List<string>();
  31.                             try {
  32.                                 sw.WriteLine("RETR 1");
  33.                                 sw.Flush();
  34.                                 if(sr.ReadLine().StartsWith("+OK")) {
  35.                                     while(sr.Peek() != '.') {
  36.                                         bericht.Add(sr.ReadLine());
  37.                                     }
  38.                                 }
  39.                                 foreach(string s in bericht) {
  40.                                     Console.WriteLine(s);
  41.                                 }
  42.                             } catch(Exception e) {
  43.                                 //fout weergeven
  44.                                 Console.WriteLine("Fout in LeesBericht van IO_MailIn: {0}",e.Message);
  45.                                 System.Diagnostics.Debug.WriteLine("Fout in LeesBericht van IO_MailIn: {0}",e.Message);
  46.                                 //fout doorgooien
  47.                                 throw e;
  48.                             }
  49.  
  50.  
  51.                             sw.WriteLine("QUIT");
  52.                             sw.Flush();
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.  
  59.         public static void Main(string[] args) {
  60.             Program p = new Program();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement