• 大小: 292KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: C#
  • 标签: E-mail  C#  

资源简介

利用smptClient类和POP3协议实现一个邮件客户端,能够收发邮件,在发送邮件时能添加附件

资源截图

代码片段和文件信息

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.Net;
using System.Net.Sockets;
using System.IO;

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

        private void label2_Click(object sender EventArgs e)
        {

        }

        private void label1_Click(object sender EventArgs e)
        {

        }

        private void button3_Click(object sender EventArgs e)
        {
            Server = new TcpClient(tBSrv.Text 110);


            try
            {
                NetStrm = Server.GetStream();
                RdStrm = new StreamReader(Server.GetStream() System.Text.Encoding.Default);
                listBoxStatus.Items.Add(RdStrm.ReadLine());
                Data = “USER “ + tBUser.Text + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData 0 szData.Length);
                listBoxStatus.Items.Add(RdStrm.ReadLine());
                Data = “PASS “ + tBPwd.Text + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData 0 szData.Length);
                listBoxStatus.Items.Add(RdStrm.ReadLine());
                Data = “STAT“ + CRLF;
                szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
                NetStrm.Write(szData 0 szData.Length);
                string st = RdStrm.ReadLine();
                listBoxStatus.Items.Add(st);
                st = st.Substring(4 st.IndexOf(“ “5) - 4);
                int count = Int32.Parse(st);
                if (count > 0) 
                {
                    listBoxOperate.Enabled = true;
                    btnRead.Enabled = true;
                    btnDelete.Enabled = true;
                    listBoxStatus.Items.Clear();
                    listBoxOperate.Items.Clear();
                    for (int i = 0; i < count; i++)
                        listBoxOperate.Items.Add(“第“ + (i + 1) + “封邮件“);
                    listBoxOperate.SelectedIndex = 0;
                }

                else
                {
                    groupBoxOpe.Text = “信箱中没有邮件“;
                    listBoxOperate.Enabled = false;
                    btnRead.Enabled = false;
                    btnDelete.Enabled = false;
                }
                btnConnect.Enabled = false;
                btnDisConnect.Enabled = true;


            }
            catch(InvalidOperationException err)
            {
            

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-27 23:06  Email\
     目录           0  2017-11-27 23:06  Email\.vs\
     目录           0  2018-11-20 10:09  Email\.vs\Email\
     目录           0  2017-11-27 23:06  Email\.vs\Email\v14\
     文件       48128  2017-12-19 08:17  Email\.vs\Email\v14\.suo
     目录           0  2018-11-20 10:11  Email\.vs\Email\v15\
     文件       54272  2018-11-20 10:21  Email\.vs\Email\v15\.suo
     目录           0  2018-11-20 10:11  Email\.vs\Email\v15\Server\
     目录           0  2018-11-20 10:11  Email\.vs\Email\v15\Server\sqlite3\
     文件           0  2018-11-20 10:11  Email\.vs\Email\v15\Server\sqlite3\db.lock
     文件        4096  2018-11-20 10:11  Email\.vs\Email\v15\Server\sqlite3\storage.ide
     文件       32768  2018-11-20 10:17  Email\.vs\Email\v15\Server\sqlite3\storage.ide-shm
     文件      688072  2018-11-20 10:20  Email\.vs\Email\v15\Server\sqlite3\storage.ide-wal
     文件         857  2017-11-27 15:20  Email\Email.sln
     文件       18944  2018-11-21 09:48  Email\Email.suo
     目录           0  2018-11-20 10:20  Email\Email\
     目录           0  2017-11-27 23:06  Email\Email\bin\
     目录           0  2017-11-27 23:06  Email\Email\bin\Debug\
     文件       14336  2018-11-21 09:38  Email\Email\bin\Debug\Email.exe
     文件       34304  2018-11-21 09:38  Email\Email\bin\Debug\Email.pdb
     文件       11600  2018-11-21 09:48  Email\Email\bin\Debug\Email.vshost.exe
     文件         490  2014-01-13 21:31  Email\Email\bin\Debug\Email.vshost.exe.manifest
     文件        3669  2017-11-27 17:24  Email\Email\Email.csproj
     文件        5938  2018-11-21 09:38  Email\Email\Form1.cs
     文件       11770  2018-11-21 09:38  Email\Email\Form1.Designer.cs
     文件        5817  2018-11-21 09:38  Email\Email\Form1.resx
     目录           0  2017-11-27 23:06  Email\Email\obj\
     目录           0  2017-11-27 23:06  Email\Email\obj\x86\
     目录           0  2018-11-21 09:38  Email\Email\obj\x86\Debug\
     文件        2855  2018-11-21 09:37  Email\Email\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6196  2018-11-21 09:38  Email\Email\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此处省略55个文件信息

评论

共有 条评论