Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i nee to retieve my mails in to my project like gmail inbox.

advance thanks
Posted
Comments
Sandeep Mewara 24-Jun-11 15:57pm    
Ok. And the issue is?

1 solution

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)
        {
            // Create a TCP client for a TCP connection
            TcpClient tcpClient = new TcpClient();
            txtLog.Text = "I say:\r\nConnect me to " + txtServer.Text + ":" + txtPort.Text + "\r\n\r\n";
            // Connect this TCP client to the server IP/name and port specified in the form
            tcpClient.Connect(txtServer.Text, Convert.ToInt32(txtPort.Text));
            // Create a network stream to retrieve data from the TCP client
            NetworkStream netStream = tcpClient.GetStream();
            // We need a stream reader to be able to read the network stream
            System.IO.StreamReader strReader = new System.IO.StreamReader(netStream);
            // If the connection was made successfully
            if (tcpClient.Connected)
            {
                txtLog.Text += "Server says:\r\n" + strReader.ReadLine() + "\r\n\r\n";
                // Buffer to which we're going to write the commands
                byte[] WriteBuffer = new byte[1024];
                // We're passing ASCII characters
                ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                // Pass the username to the server
                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";
                // Pass the password to the server
                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";
                // Now that we are (probably) authenticated, list the messages
                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 == ".")
                    {
                        // It's the last message so exit the loop and continue
                        break;
                    }
                    else
                    {
                        // List the message
                        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();
            }
        }
/// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        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();
            // 
            // button1
            // 
            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);
            // 
            // txtLog
            // 
            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;
            // 
            // txtPort
            // 
            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";
            // 
            // txtPass
            // 
            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;
            // 
            // label1
            // 
            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:";
            // 
            // label2
            // 
            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:";
            // 
            // label3
            // 
            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:";
            // 
            // label4
            // 
            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:";
            // 
            // txtUser
            // 
            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;
            // 
            // txtServer
            // 
            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;
            // 
            // btnConnect
            // 
            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);
            // 
            // label5
            // 
            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:";
            // 
            // Form1
            // 
            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;
    }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900