Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using that code but i can't read my mail in form 1 please guide me please please help me to much error showing

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Web;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;


namespace retrieveing_of_gmail
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            {
                try
                {
                    // create an instance of TcpClient
                    TcpClient tcpclient = new TcpClient();
                    // HOST NAME POP SERVER and gmail uses port number 995 for POP
                    tcpclient.Connect("pop.gmail.com", 995);

                    // This is Secure Stream // opened the connection between client and POP Server
                    System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
                    // authenticate as client
                    sslstream.AuthenticateAsClient("pop.gmail.com");
                    //bool flag = sslstream.IsAuthenticated;   // check flag
                    // Asssigned the writer to stream
                    System.IO.StreamWriter sw = new StreamWriter(sslstream);
                    // Assigned reader to stream
                    System.IO.StreamReader reader = new StreamReader(sslstream);
                    // refer POP rfc command, there very few around 6-9 command
                    sw.WriteLine("USER your_gmail_user_name@gmail.com");
                    // sent to server
                    sw.Flush();
                    sw.WriteLine("PASS your_gmail_password");
                    sw.Flush();
                    // this will retrive your first email
                    sw.WriteLine("RETR 1");
                    sw.Flush();
                    // close the connection
                    sw.WriteLine("Quit ");
                    sw.Flush();
                    string str = string.Empty;
                    string strTemp = string.Empty;
                    while ((strTemp = reader.ReadLine()) != null)
                    {
                        // find the . character in line
                        if (strTemp == ".")
                        {
                            break;
                        }
                        if (strTemp.IndexOf("-ERR") != -1)
                        {
                            break;
                        }
                        str += strTemp;
                    }
                    MessageBox.Show(str);
                    //  Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
                }
                catch (Exception)
                {
                    //  Response.Write(ex.Message);
                }
            }

        }
        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
        }
        private void button3_Click(object sender, EventArgs e)
        {
            { // retrival of hotmail
                try
                {
                    // create an instance of TcpClient
                    TcpClient tcpclient = new TcpClient();
                    // HOST NAME POP SERVER and gmail uses port number 995 for POP
                    tcpclient.Connect("pop3.live.com", 995);
                    // This is Secure Stream // opened the connection between client and POP Server
                    System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
                    // authenticate as client
                    sslstream.AuthenticateAsClient("pop3.live.com");
                    //bool flag = sslstream.IsAuthenticated; // check flag
                    // Asssigned the writer to stream
                    System.IO.StreamWriter sw = new StreamWriter(sslstream);
                    // Assigned reader to stream
                    System.IO.StreamReader reader = new StreamReader(sslstream);
                    // refer POP rfc command, there very few around 6-9 command
                    sw.WriteLine("USER your_hotmail_user_name@hotmail.com");
                    // sent to server
                    sw.Flush();
                    sw.WriteLine("PASS your_hotmail_password");
                    sw.Flush();
                    // RETR 1 will retrive your first email.
                    // It will read content of your first email.
                    sw.WriteLine("RETR 1");
                    sw.Flush();

                    // close the connection
                    sw.WriteLine("Quit ");
                    sw.Flush();

                    string str = string.Empty;
                    string strTemp = string.Empty; while ((strTemp = reader.ReadLine()) != null)
                    {
                        // find the . character in line
                        if (strTemp == ".")
                        {
                            break;
                        }
                        if (strTemp.IndexOf("-ERR") != -1)
                        {
                            break;
                        }
                        str += strTemp;
                    }
                    MessageBox.Show(str);
                    //  Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
                }
                catch (Exception ex)
                {
                    //  Response.Write(ex.Message);
                }
            }

        }
        private void button5_Click(object sender, EventArgs e)
        {

        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
Posted
Updated 11-Nov-10 20:00pm
v2
Comments
Abhinav S 12-Nov-10 2:00am    
Which line throws the error?
Rajesh Anuhya 12-Nov-10 2:03am    
What is the Error ???,
shakil0304003 12-Nov-10 2:08am    
Give the error message.

1 solution

Why don't you use this :
<code>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
protected void Button9_Click(object sender, EventArgs e) 
{
try
{
// create an instance of TcpClient 
TcpClient tcpclient = new TcpClient();     
// HOST NAME POP SERVER and gmail uses port number 995 for POP 
tcpclient.Connect("pop.gmail.com", 995); 

// This is Secure Stream // opened the connection between client and POP Server
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
// authenticate as client  
 sslstream.AuthenticateAsClient("pop.gmail.com"); 
//bool flag = sslstream.IsAuthenticated;   // check flag 
// Asssigned the writer to stream 
System.IO.StreamWriter sw = new StreamWriter(sslstream); 
// Assigned reader to stream
System.IO.StreamReader reader = new StreamReader(sslstream); 
// refer POP rfc command, there very few around 6-9 command
sw.WriteLine("USER your_gmail_user_name@gmail.com"); 
// sent to server
sw.Flush(); 
sw.WriteLine("PASS your_gmail_password"); 
sw.Flush();
// this will retrive your first email 
sw.WriteLine("RETR 1"); 
sw.Flush();
// close the connection
sw.WriteLine("Quit "); 
sw.Flush();
string str = string.Empty; 
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null) 
{
// find the . character in line
if (strTemp == ".") 
{
break; 
}
if (strTemp.IndexOf("-ERR") != -1) 
{
break; 
}
str += strTemp;
}
Response.Write(str);
Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email "); 
}
catch (Exception ex) 
{
Response.Write(ex.Message);
}
}</code>


Try using this.
 
Share this answer
 
Comments
Vinoth Arun Raj. X 10-Dec-10 1:39am    
This is in Encrypted format how to change it to normal

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