基本信息
源码名称:C# 收发邮件工具源码(邮箱小助手)
源码大小:4.86M
文件格式:.rar
开发语言:C#
更新时间:2018-02-24
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
支持发送带附件的邮件,支持读取接收到的邮件,发送邮件、接收邮件内容 均测试通过了

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Mail;
using LumiSoft.Net.POP3.Client;
using System.Net.Sockets;
using System.Net.Mime;
using System.Net;
using System.IO;
using LumiSoft.Net.Mail;

namespace WindowsFormsmail
{
    
    public partial class Form1 : Form
    {
        public TcpClient Server;
        public NetworkStream NetStrm;
        public StreamReader RdStrm;
        public string Data;
        public byte[] szData;
        public string CRLF = Environment.NewLine;
        POP3_Client client;
        pop mypop = new pop();

        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "renqian@northcom.cn";
            textBox5.Text = "******";
           // textBox2.Text = "chensong@northcom.cn";
            comboBox1.Items.Add("smtp.163.com");
           // comboBox1.Items.Add("smtp.gmail.com");
            comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        private void button1_Click(object sender, EventArgs e)
        {       
            try
            {
               System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient(comboBox1.Text);
                string strFrom = string.Empty;
                if (comboBox1.SelectedItem.ToString() == "smtp.163.com")
                {
                    strFrom = textBox1.Text;
                }
                MailAddress from = new MailAddress(strFrom, "任乾", Encoding.UTF8);
                MailAddress to = new MailAddress(textBox2.Text, "小明", Encoding.UTF8);
                MailMessage Mail= new MailMessage(from, to);
                #region
                //附件部分
                foreach (TreeNode tree in treeView1.Nodes) {
                    string filename = tree.Text;
                    if (File.Exists(filename))
                    {
                        Attachment attach = new Attachment(filename);
                        ContentDisposition disposition = attach.ContentDisposition;
                        disposition.CreationDate = System.IO.File.GetCreationTime(filename);
                        disposition.ModificationDate = System.IO.File.GetLastWriteTime(filename);
                        disposition.ReadDate = System.IO.File.GetLastAccessTime(filename);
                        Mail.Attachments.Add(attach);
                    }
                    else {
                        MessageBox.Show("文件未找到");
                    }
                }
                #endregion
                Mail.Subject = textBox3.Text;
                Mail.SubjectEncoding = Encoding.UTF8;
                Mail.Body = textBox4.Text;
                Mail.BodyEncoding = Encoding.UTF8;
                Client.DeliveryMethod = SmtpDeliveryMethod.Network;                     
               //Client.EnableSsl = true;
              // Client.UseDefaultCredentials = false;             
                string username = textBox1.Text;
                string passwd = textBox5.Text;
                NetworkCredential myCredentials = new NetworkCredential(username, passwd);             
                Client.Credentials = myCredentials;
                Client.Port = 25;
                Client.Host = "smtp.qiye.163.com";
                Client.Send(Mail);
                MessageBox.Show("发送成功!");
            }
            catch(Exception ex) {
                MessageBox.Show(ex.Message);
            }           
        }
        #region
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
        #endregion
        //添加附件按钮
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();
            openFile.ValidateNames = true;
            openFile.Filter = "所有文件(*.*)|*.*";
            if (openFile.ShowDialog() == DialogResult.OK) {
                string filename = openFile.FileName;
                treeView1.Nodes.Add(filename);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        //删除附件按钮
        private void button5_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode == null)
            {
                MessageBox.Show("请选择要删除的附件。");
            }
            else {
                TreeNode tree = treeView1.SelectedNode;
                treeView1.Nodes.Remove(tree);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            //gtf---建立服务器连接
            client= mypop.Connect();
            List<Mail_Message> dd = mypop.GetEmails(client);
           
            
            foreach (Mail_Message mdd in dd) {
                textBoxmailsIn.Text  = "Mail:"   mdd.BodyText   CRLF;
            }

            //Cursor cr = Cursor.Current;
           // Cursor.Current = Cursors.WaitCursor;
            #region
            string szTemp=string.Empty;
            try {
                listBox1.Items.Add("Success");
                //Cursor.Current = cr;
            }
            catch (Exception err)
            {
                listBox1.Items.Add("Error: "   err.ToString());
            }
            #endregion
        }

        private void button7_Click(object sender, EventArgs e)
        {
           // Cursor cr = Cursor.Current;
           // Cursor.Current = Cursors.WaitCursor;
            listBox1.Items.Clear();
            try
            {
                client = mypop.Connect();
                listBox1.Items.Add("Connected");
               // Cursor.Current = cr;
            }
            catch (Exception err)
            {
                listBox1.Items.Add("Error: "   err.ToString());

            }
        }
    }
}