• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#编写电子油箱

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

第一步:新建一个windows应用程序,命名为:Mail,并为生成的窗体添加相应的控件,效果图如下:

第二步,为控件添加相应的代码事件:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace Mail
{
    public partial class Form1 : Form
    {
        public TcpClient Server;
        public NetworkStream NetStrm;
        public StreamReader RdStrm;
        public string Data;
        public byte[] szData;
        public string CRLF = "\r\n";
        public Form1()
        {
            InitializeComponent();
        }

        private void Connect_Click(object sender, EventArgs e)
        {
            Cursor cr = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            Server = new TcpClient(Popserver.Text,110);
            Status.Items.Clear();
            try
            {
                NetStrm = Server.GetStream();
                RdStrm = new StreamReader(Server.GetStream());
                Status.Items.Add(RdStrm.ReadLine());
                Data = "USER" + Username.Text + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Status.Items.Add(RdStrm.ReadLine());
                Data = "STAT" + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                Status.Items.Add(RdStrm.ReadLine());
                Connect.Enabled = false;
                Disconnect.Enabled = true;
                Retrieve.Enabled = true;
                Cursor.Current = cr;
            }
            catch (InvalidOperationException err)
            {
                Status.Items.Add("ERROR:" + err.ToString());
            }
        }

        private void Disconnect_Click(object sender, EventArgs e)
        {
            Cursor cr = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            Data = "QUIT" + CRLF;
            szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
            NetStrm.Write(szData, 0, szData.Length);
            Status.Items.Add(RdStrm.ReadLine());
            NetStrm.Close();
            RdStrm.Close();
            Connect.Enabled = true;
            Disconnect.Enabled = false;
            Retrieve.Enabled = false;
            Cursor.Current = cr;
        }

        private void Retrieve_Click(object sender, EventArgs e)
        {

            Cursor cr = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            String szTemp;
            Message.Clear();
            try
            {
                Data = "RETR" + Mailnum.Text + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData, 0, szData.Length);
                szTemp = RdStrm.ReadLine();
                if (szTemp[0] != '-')
                {
                    while (szTemp != ".")
                    {
                        Message.Text += szTemp;
                        szTemp = RdStrm.ReadLine();
                    }
                    if (BackupChBox.Checked == false)
                    {

                        Data = "DELE" + Mailnum.Text + CRLF;
                        szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                        NetStrm.Write(szData, 0, szData.Length);
                        Status.Items.Add(RdStrm.ReadLine());
                    }
                }
                else
                {
                    Status.Items.Add(szTemp);
                }
                Cursor.Current = cr;
            }
            catch (InvalidExpressionException err)
            {
                Status.Items.Add("ERROR" + err.ToString());
            }
        }
    }
}
说明:这只是一个简单的通讯编程,实现的功能也只是收取邮件,发送邮件功能的实现,需要等待......


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Excel2007 导出生成 2003兼容格式发布时间:2022-07-14
下一篇:
c#接口和抽象类的区别发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap