Lesnikowski.Pawel.Mail.Pop3.Pop3.Connect C# (CSharp) Method

Connect() public method

public Connect ( ) : void
return void
        public void Connect()
        {
            if (host==null)
                throw new Exception("no host");

            IPHostEntry hostEntry = Dns.GetHostEntry(host);

            if (hostEntry==null)
                throw new Exception("can't get ip");

            // construct the endpoint
            IPEndPoint endPoint=new IPEndPoint(hostEntry.AddressList[0],port);

            if (endPoint==null)
                throw new Exception("can't get endpoint");

            // initialize socket
            socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);

            // set the socket timeout
            //socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, sendTimeout);
            //socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, receiveTimeout);

            socket.Connect(endPoint);
            ReceiveLine();
        }

Usage Example

Ejemplo n.º 1
0
		static void Main(string[] args)
		{
			Pop3 pop3=new Pop3();
			pop3.host="10.1.1.123";
			pop3.userName="******";
			pop3.password="******";

			pop3.Connect();
			pop3.Login();
			pop3.GetAccountStat();

			for(int i=1;i<=pop3.messageCount;i++)
			{
				Pop3Message message=pop3.GetMessageHeader(i);

				Console.WriteLine("--mail header #"+i.ToString());
				Console.WriteLine(message.from);
				Console.WriteLine(message.subject);
				Console.WriteLine(message.replyTo);
				Console.WriteLine(message.date);
				Console.WriteLine(message.contentType);
				Console.WriteLine(message.charset);
				
			}
			
			for (int j=1;j<=pop3.messageCount;j++)
			{
				Console.WriteLine("-----first mail all:------");
				Pop3Message message=pop3.GetMessage(j);

				Console.WriteLine(message.from);
				Console.WriteLine(message.subject);

				if (message.hasAttachments==true)
				{
                    DumpAttachments( message.attachments );
					
				}
				else
					Console.WriteLine("body:"+message.body);
			}
			pop3.Close();
			Console.WriteLine("END.");
			Console.ReadLine();
		}
All Usage Examples Of Lesnikowski.Pawel.Mail.Pop3.Pop3::Connect