无法在.net中阅读我的邮件 [英] can't read my mails in .net

查看:36
本文介绍了无法在.net中阅读我的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用该代码,但我无法阅读表格1中的邮件,请指导我,请帮助我解决显示错误的许多问题

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)
        {

        }
    }
}

推荐答案

为什么不使用它:
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.


这篇关于无法在.net中阅读我的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆