using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net.Sockets;
using System.IO;
using System.Windows.Forms;
namespace Pop3Check
{
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
TcpClient tcpClient = new TcpClient();
txtLog.Text = "I say:\r\nConnect me to " + txtServer.Text + ":" + txtPort.Text + "\r\n\r\n";
tcpClient.Connect(txtServer.Text, Convert.ToInt32(txtPort.Text));
NetworkStream netStream = tcpClient.GetStream();
System.IO.StreamReader strReader = new System.IO.StreamReader(netStream);
if (tcpClient.Connected)
{
txtLog.Text += "Server says:\r\n" + strReader.ReadLine() + "\r\n\r\n";
byte[] WriteBuffer = new byte[1024];
ASCIIEncoding enc = new System.Text.ASCIIEncoding();
WriteBuffer = enc.GetBytes("USER " + txtUser.Text + "\r\n");
txtLog.Text += "I say:\r\nHere's the username: " + txtUser.Text + "\r\n\r\n";
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
txtLog.Text += "Server says\r\n" + strReader.ReadLine() + "\r\n\r\n";
WriteBuffer = enc.GetBytes("PASS " + txtPass.Text + "\r\n");
txtLog.Text += "I say:\r\nHere's the password: " + txtPass.Text + "\r\n\r\n";
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
txtLog.Text += "Server says:\r\n" + strReader.ReadLine() + "\r\n\r\n";
WriteBuffer = enc.GetBytes("LIST\r\n");
txtLog.Text += "I say:\r\nPlease list the messages\r\n\r\n";
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
string ListMessage;
while (true)
{
ListMessage = strReader.ReadLine();
if (ListMessage == ".")
{
break;
}
else
{
txtLog.Text += "Server says:\r\n" + ListMessage + "\r\n\r\n";
continue;
}
}
txtLog.Text += "I say:\r\nThanks, we will disconnect now\r\n\r\n";
WriteBuffer = enc.GetBytes("QUIT\r\n");
netStream.Write(WriteBuffer, 0, WriteBuffer.Length);
txtLog.Text += "Server says:\r\n" + strReader.ReadLine();
}
}
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.txtLog = new System.Windows.Forms.TextBox();
this.txtPort = new System.Windows.Forms.TextBox();
this.txtPass = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtUser = new System.Windows.Forms.TextBox();
this.txtServer = new System.Windows.Forms.TextBox();
this.btnConnect = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(-66, -29);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.txtLog.Location = new System.Drawing.Point(12, 114);
this.txtLog.Multiline = true;
this.txtLog.Name = "txtLog";
this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtLog.Size = new System.Drawing.Size(401, 444);
this.txtLog.TabIndex = 1;
this.txtPort.Location = new System.Drawing.Point(298, 10);
this.txtPort.Name = "txtPort";
this.txtPort.Size = new System.Drawing.Size(57, 20);
this.txtPort.TabIndex = 2;
this.txtPort.Text = "110";
this.txtPass.Location = new System.Drawing.Point(298, 36);
this.txtPass.Name = "txtPass";
this.txtPass.Size = new System.Drawing.Size(115, 20);
this.txtPass.TabIndex = 3;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 13);
this.label1.TabIndex = 4;
this.label1.Text = "POP3 Server:";
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(236, 13);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Port:";
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(26, 43);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(58, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Username:";
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(236, 39);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Password:";
this.txtUser.Location = new System.Drawing.Point(90, 36);
this.txtUser.Name = "txtUser";
this.txtUser.Size = new System.Drawing.Size(125, 20);
this.txtUser.TabIndex = 8;
this.txtServer.Location = new System.Drawing.Point(90, 10);
this.txtServer.Name = "txtServer";
this.txtServer.Size = new System.Drawing.Size(125, 20);
this.txtServer.TabIndex = 9;
this.btnConnect.Location = new System.Drawing.Point(328, 62);
this.btnConnect.Name = "btnConnect";
this.btnConnect.Size = new System.Drawing.Size(85, 28);
this.btnConnect.TabIndex = 10;
this.btnConnect.Text = "Connect";
this.btnConnect.UseVisualStyleBackColor = true;
this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 98);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(28, 13);
this.label5.TabIndex = 11;
this.label5.Text = "Log:";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(425, 570);
this.Controls.Add(this.label5);
this.Controls.Add(this.btnConnect);
this.Controls.Add(this.txtServer);
this.Controls.Add(this.txtUser);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtPass);
this.Controls.Add(this.txtPort);
this.Controls.Add(this.txtLog);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "POP3Check";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtLog;
private System.Windows.Forms.TextBox txtPort;
private System.Windows.Forms.TextBox txtPass;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtUser;
private System.Windows.Forms.TextBox txtServer;
private System.Windows.Forms.Button btnConnect;
private System.Windows.Forms.Label label5;
}
}
}