在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例桌面应用界面/GUI → C# 收发邮件工具源码(邮箱小助手)

C# 收发邮件工具源码(邮箱小助手)

桌面应用界面/GUI

下载此实例
  • 开发语言:C#
  • 实例大小:4.86M
  • 下载次数:107
  • 浏览次数:982
  • 发布时间:2018-02-24
  • 实例类别:桌面应用界面/GUI
  • 发 布 人:1392715717
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 邮箱

实例介绍

【实例简介】支持发送带附件的邮件,支持读取接收到的邮件,发送邮件、接收邮件内容 均测试通过了

【实例截图】

from clipboard

from clipboard

【核心代码】

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());

            }
        }
    }
}

标签: 邮箱

实例下载地址

C# 收发邮件工具源码(邮箱小助手)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警