C#利用Lumisoft组件实现收邮解析邮件功能

一、 POP3协议简介 1、什么是POP3协议:
邮局协议(Post Office Protocol,简称POP)是TCP/IP协议族中的一员,由RFC 1939 定义。本协议主要用于支持使用客户端远程管理在服务器上的电子邮件。最新版本为POP3,全名“Post Office Protocol - Version 3”,而提供了SSL加密的POP3协议被称为POP3S。
2、POP3协议具体过程:
POP 协议支持“离线”邮件处理。其具体过程是:邮件发送到服务器上,电子邮件客户端调用邮件客户机程序以连接服务器,并下载所有未阅读的电子邮件。这种离线访问模式是一种存储转发服务,将邮件从邮件服务器端送到个人终端机器上,一般是PC机或 MAC。一旦邮件发送到 PC 机或MAC上,邮件服务器上的邮件将会被删除。但目前的POP3邮件服务器大都可以“只下载邮件,服务器端并不删除”,也就是改进的POP3协议。
3、电子邮件系统的基本网络结构
C#利用Lumisoft组件实现收邮解析邮件功能
文章图片

二、 运用C#实现POP3接收邮件的三种方法 【C#利用Lumisoft组件实现收邮解析邮件功能】1、 利用Socket组件
socket本质是编程接口,是对TCP/IP的封装。TCP/IP是传输层的协议。POP3是应用层的协议,是基于TCP/IP协议的。所以,使用socket实现上述几种协议的客户端,其实是对借助socket对TCP/IP数据传输的封装基础,再往上封装一层的。
POP3只需要建立一个连接,客户端向服务器发命令,服务器向客户端返回数据就行了。具体就是通过socket发命令,再通过socket接数据 。
具体实现如下图(实现代码不再详细阐述):
C#利用Lumisoft组件实现收邮解析邮件功能
文章图片

该POP3客户端主要实现的就是接收邮件功能了,然而并没有实现邮件内容解析功能。
并且在连接过程中,163、126、sina等邮箱均可以登录至相应的pop服务器,唯独QQ邮箱受阻,提示信息为:-err login fail a secure connection is required(such as ssl),所以需要建立ssl的相关安全连接才可以登录至pop服务器,因此放弃该方法,所以选择方法三
2、 利用OpenPop组件
这是一款可以支持 SSL 收发邮件的控件,和LumiSoft组件类似,自己在使用LumiSoft之前对OpenPop组件进行了测试,其中邮件解析的各项数据较全。但是OpenSmtp组件连接不了ssl,这个只对pop协议适用,而LumiSoft对所有的邮件传输协议均适用,所以选择了方法三。
运行效果如下图:
C#利用Lumisoft组件实现收邮解析邮件功能
文章图片

3、 利用LumiSoft组件
LumiSoft.Net是非常强大的开源组件,不仅仅发送邮件,同样也可用于接收邮件,在这周的学习时间里是个人找到的最好的开源组件了。阅读LumiSoft.Net的源代码,可以看到LumiSoft.Net编程严格遵循了RFC(Request For Comments)定义的协议规范。通过阅读这些源码对于了解RFC和其中关于邮件网络协议规范也是非常有帮助的。
如果要查阅RFC文档可以通过LumiSoft组件链接网站查询。
运行效果如下图:
主界面:
C#利用Lumisoft组件实现收邮解析邮件功能
文章图片

解析:
C#利用Lumisoft组件实现收邮解析邮件功能
文章图片

三、 运用LumiSoft组件实现接收邮件 1、 运用的命名空间

using System using System.Windows.Forms; using System.IO; using LumiSoft.Net; using LumiSoft.Net.Mail; using LumiSoft.Net.POP3.Client; using LumiSoft.Net.MIME;

2、 连接并获取信息部分
(1)、连接到POP3服务器
POP3_Client.Connect函数主要是连接pop服务器,端口,是否用ssl
POP3_Client.Authenticate函数主要验证邮箱和邮箱授权码(通常为16位)
private void btn_connect_Click(object sender, EventArgs e) { if (txt_username.Text == "") { MessageBox.Show(this, "Please fill user name !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }POP3_Client pop3 = new POP3_Client(); try { pop3.Connect(txt_server.Text, (int)number_port.Value, cb_isSSL.Checked); pop3.Authenticate(txt_username.Text, txt_password.Text, true); m_pPop3 = pop3; this.DialogResult = DialogResult.OK; FillMessagesList(); } catch (Exception x) { MessageBox.Show(this, "POP3 server returned: " + x.Message + " !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); pop3.Dispose(); } }

(2)、获取邮件头信息函数FillMessagesList()
通过POP3_ClientMessage、Mail_Message获取信息,并写进ListViewItem的项内,然后传递给lst_message的Item,以达到在窗体中显示的目的。
private void FillMessagesList() { this.Cursor = Cursors.WaitCursor; try { foreach (POP3_ClientMessage message in m_pPop3.Messages) { Mail_Message mime = Mail_Message.ParseFromByte(message.HeaderToByte()); Mail_Message mime2 = Mail_Message.ParseFromByte(message.MessageToByte()); ListViewItem item = new ListViewItem(); if (mime.From != null) { item.Text = mime.From.ToString(); } else { item.Text = ""; }if (string.IsNullOrEmpty(mime.Subject)) { item.SubItems.Add(""); } else { item.SubItems.Add(mime.Subject); } item.SubItems.Add(mime.Date.ToString()); item.SubItems.Add(((decimal)(message.Size / (decimal)1000)).ToString("f2") + " kb"); if (mime.Cc != null) { item.SubItems.Add(Convert.ToString(mime.Cc)); } else { item.SubItems.Add(""); } if (mime.Bcc != null) { item.SubItems.Add(Convert.ToString(mime.Bcc)); } else { item.SubItems.Add(""); } item.SubItems.Add(mime.ContentTransferEncoding); item.SubItems.Add(mime.MessageID); item.SubItems.Add(mime.MimeVersion); item.SubItems.Add(Convert.ToString(mime.Received)); item.SubItems.Add(mime2.BodyHtmlText); item.SubItems.Add(Convert.ToString(mime.ContentType)); item.SubItems.Add(Convert.ToString(mime.IsDisposed)); item.SubItems.Add(Convert.ToString(mime.IsModified)); item.Tag = message; lst_messages.Items.Add(item); } } catch (Exception x) { MessageBox.Show(this, "Error: " + x.Message, "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }

(3)、SSL判断函数
通过WellKnownPorts方法自动获取各个邮件服务器所在ssl或者非ssl状态下对应的端口。
private void cb_isSSL_CheckedChanged_1(object sender, EventArgs e) { if (cb_isSSL.Checked) { number_port.Value = https://www.it610.com/article/WellKnownPorts.POP3_SSL; } else { number_port.Value = WellKnownPorts.POP3; } }

3、 通过窗体获取具体解析的信息部分
(1)、邮件列表内点击行为
通过点击邮件列表内的邮件项这一选择行为,会相应地在下面附件栏和正文栏显示出对应的信息,并把邮件头解析信息返回至txt_Header,其中用到了POP3_ClientMessage、Mail_Message、MIME_Entity方法。
private void lst_messages_SelectedIndexChanged(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; try { toolStrip1.Items["save"].Enabled = false; toolStrip1.Items["delete"].Enabled = false; if (lst_messages.SelectedItems.Count > 0) { lst_attachment.Items.Clear(); txt_Body.Text = ""; POP3_ClientMessage message = (POP3_ClientMessage)lst_messages.SelectedItems[0].Tag; Mail_Message mime = Mail_Message.ParseFromByte(message.MessageToByte()); string Sender = mime.From == null ? "Sender is null" : mime.From[0].DisplayName; string senderAddress = mime.From == null ? "senderAddress is null" : mime.From[0].Address; string subject = mime.Subject ?? "subject is null"; string recDate = mime.Date == DateTime.MinValue ? "date not specified" : mime.Date.ToString(); string content = mime.BodyText ?? "content is null"; foreach (MIME_Entity entity in mime.Attachments) { ListViewItem item = new ListViewItem(); if (entity.ContentDisposition != null && entity.ContentDisposition.Param_FileName != null) { item.Text = entity.ContentDisposition.Param_FileName; } else { item.Text = "untitled"; } item.Tag = entity; lst_attachment.Items.Add(item); }if (mime.BodyText != null) { txt_Body.Text = mime.BodyText; } if (mime.Header != null) { txt_Header.Text = Convert.ToString(mime.Header); } toolStrip1.Items["save"].Enabled = true; toolStrip1.Items["delete"].Enabled = true; } } catch (Exception x) { MessageBox.Show(this, "Error: " + x.Message, "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Cursor = Cursors.Default; }

(2)、邮件列表内保存及删除行为
在toolStrip上生成两个button,分别对应保存及删除。
private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { if (string.Equals(e.ClickedItem.Name, "save")) { SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = "message.eml"; if (dlg.ShowDialog() == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; POP3_ClientMessage message = (POP3_ClientMessage)lst_messages.SelectedItems[0].Tag; File.WriteAllBytes(dlg.FileName, message.MessageToByte()); this.Cursor = Cursors.Default; } } else if (string.Equals(e.ClickedItem.Name, "delete")) { if (MessageBox.Show(this, "Do you want to delete selected message ?", "Confirm Delete:", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { POP3_ClientMessage message = (POP3_ClientMessage)lst_messages.SelectedItems[0].Tag; message.MarkForDeletion(); lst_messages.SelectedItems[0].Remove(); } } }

(3)、附件列表内点击行为
通过鼠标右键点击“Save”可以把附件下载至本地
1、右键点击生成菜单函数:
private void lst_attachment_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right && lst_attachment.SelectedItems.Count > 0) { ContextMenuStrip menu = new ContextMenuStrip(); menu.Items.Add("Save"); menu.ItemClicked += new ToolStripItemClickedEventHandler(menu_ItemClicked); menu.Show(Control.MousePosition); } }

2、点击“Save”保存函数:
private void menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { MIME_Entity entity = (MIME_Entity)lst_attachment.SelectedItems[0].Tag; SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = lst_attachment.SelectedItems[0].Text; if (dlg.ShowDialog(this) == DialogResult.OK) { File.WriteAllBytes(dlg.FileName, ((MIME_b_SinglepartBase)entity.Body).Data); } }

Mail.Designer.cs
namespace POP_Email { partial class Mail { /// /// 必需的设计器变量。 /// private System.ComponentModel.IContainer components = null; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }#region Windows 窗体设计器生成的代码/// /// 设计器支持所需的方法 - 不要修改 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Mail)); this.delete = new System.Windows.Forms.ToolStripButton(); this.save = new System.Windows.Forms.ToolStripButton(); this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.label6 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.txt_Body = new System.Windows.Forms.TextBox(); this.lst_attachment = new System.Windows.Forms.ListView(); this.lst_messages = new System.Windows.Forms.ListView(); this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader10 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader9 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader11 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader12 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader16 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader17 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.toolStrip1 = new System.Windows.Forms.ToolStrip(); this.label1 = new System.Windows.Forms.Label(); this.number_port = new System.Windows.Forms.NumericUpDown(); this.label2 = new System.Windows.Forms.Label(); this.txt_password = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.txt_username = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.btn_cancel = new System.Windows.Forms.Button(); this.btn_connect = new System.Windows.Forms.Button(); this.cb_isSSL = new System.Windows.Forms.CheckBox(); this.txt_server = new System.Windows.Forms.TextBox(); this.skinEngine1 = new Sunisoft.IrisSkin.SkinEngine(((System.ComponentModel.Component)(this))); this.tabPage2 = new System.Windows.Forms.TabPage(); this.txt_Header = new System.Windows.Forms.TextBox(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.toolStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.number_port)).BeginInit(); this.tabPage2.SuspendLayout(); this.SuspendLayout(); // // delete // this.delete.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.delete.Image = ((System.Drawing.Image)(resources.GetObject("delete.Image"))); this.delete.ImageTransparentColor = System.Drawing.Color.Magenta; this.delete.Name = "delete"; this.delete.RightToLeft = System.Windows.Forms.RightToLeft.No; this.delete.Size = new System.Drawing.Size(23, 29); this.delete.Tag = "delete"; this.delete.Text = "Delete"; // // save // this.save.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.save.Image = ((System.Drawing.Image)(resources.GetObject("save.Image"))); this.save.ImageTransparentColor = System.Drawing.Color.Magenta; this.save.Name = "save"; this.save.Size = new System.Drawing.Size(23, 29); this.save.Tag = "save"; this.save.Text = "Save"; // // columnHeader4 // this.columnHeader4.Text = "大小"; this.columnHeader4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.columnHeader4.Width = 115; // // columnHeader3 // this.columnHeader3.Text = "时间"; this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.columnHeader3.Width = 121; // // columnHeader2 // this.columnHeader2.Text = "主题"; this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.columnHeader2.Width = 200; // // columnHeader1 // this.columnHeader1.Text = "发件人"; this.columnHeader1.Width = 131; // // tabControl1 // this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Location = new System.Drawing.Point(15, 89); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(860, 538); this.tabControl1.TabIndex = 35; // // tabPage1 // this.tabPage1.Controls.Add(this.label6); this.tabPage1.Controls.Add(this.label5); this.tabPage1.Controls.Add(this.txt_Body); this.tabPage1.Controls.Add(this.lst_attachment); this.tabPage1.Controls.Add(this.lst_messages); this.tabPage1.Controls.Add(this.toolStrip1); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.tabPage1.Size = new System.Drawing.Size(852, 512); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "接收端"; this.tabPage1.UseVisualStyleBackColor = true; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(3, 335); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(41, 12); this.label6.TabIndex = 5; this.label6.Text = "正文:"; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(3, 237); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(41, 12); this.label5.TabIndex = 4; this.label5.Text = "附件:"; this.label5.Click += new System.EventHandler(this.label5_Click); // // txt_Body // this.txt_Body.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txt_Body.Location = new System.Drawing.Point(5, 359); this.txt_Body.Multiline = true; this.txt_Body.Name = "txt_Body"; this.txt_Body.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txt_Body.Size = new System.Drawing.Size(841, 136); this.txt_Body.TabIndex = 3; // // lst_attachment // this.lst_attachment.Location = new System.Drawing.Point(3, 252); this.lst_attachment.Name = "lst_attachment"; this.lst_attachment.Size = new System.Drawing.Size(844, 67); this.lst_attachment.TabIndex = 2; this.lst_attachment.UseCompatibleStateImageBehavior = false; this.lst_attachment.View = System.Windows.Forms.View.SmallIcon; this.lst_attachment.MouseClick += new System.Windows.Forms.MouseEventHandler(this.lst_attachment_MouseClick_2); // // lst_messages // this.lst_messages.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.lst_messages.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.columnHeader1, this.columnHeader2, this.columnHeader3, this.columnHeader4, this.columnHeader5, this.columnHeader6, this.columnHeader7, this.columnHeader10, this.columnHeader8, this.columnHeader9, this.columnHeader11, this.columnHeader12, this.columnHeader16, this.columnHeader17}); this.lst_messages.FullRowSelect = true; this.lst_messages.HideSelection = false; this.lst_messages.Location = new System.Drawing.Point(5, 38); this.lst_messages.MultiSelect = false; this.lst_messages.Name = "lst_messages"; this.lst_messages.Size = new System.Drawing.Size(844, 186); this.lst_messages.TabIndex = 1; this.lst_messages.UseCompatibleStateImageBehavior = false; this.lst_messages.View = System.Windows.Forms.View.Details; this.lst_messages.SelectedIndexChanged += new System.EventHandler(this.lst_messages_SelectedIndexChanged_2); // // columnHeader5 // this.columnHeader5.Text = "抄送"; this.columnHeader5.Width = 114; // // columnHeader6 // this.columnHeader6.Text = "密送"; this.columnHeader6.Width = 97; // // columnHeader7 // this.columnHeader7.Text = "编码"; // // columnHeader10 // this.columnHeader10.Text = "MessageID"; this.columnHeader10.Width = 300; // // columnHeader8 // this.columnHeader8.Text = "MimeVersion"; this.columnHeader8.Width = 200; // // columnHeader9 // this.columnHeader9.Text = "Received"; this.columnHeader9.Width = 200; // // columnHeader11 // this.columnHeader11.Text = "BodyHtmlText"; this.columnHeader11.Width = 200; // // columnHeader12 // this.columnHeader12.Text = "ContentType"; this.columnHeader12.Width = 200; // // columnHeader16 // this.columnHeader16.Text = "IsDisposed"; this.columnHeader16.Width = 200; // // columnHeader17 // this.columnHeader17.Text = "IsModified"; this.columnHeader17.Width = 200; // // toolStrip1 // this.toolStrip1.AutoSize = false; this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.save, this.delete}); this.toolStrip1.Location = new System.Drawing.Point(3, 3); this.toolStrip1.Name = "toolStrip1"; this.toolStrip1.Size = new System.Drawing.Size(846, 32); this.toolStrip1.TabIndex = 0; this.toolStrip1.Text = "tool_Messages"; this.toolStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.toolStrip1_ItemClicked); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(10, 17); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(53, 12); this.label1.TabIndex = 24; this.label1.Text = "服务器:"; // // number_port // this.number_port.Location = new System.Drawing.Point(50, 51); this.number_port.Maximum = new decimal(new int[] { 1000, 0, 0, 0}); this.number_port.Name = "number_port"; this.number_port.Size = new System.Drawing.Size(43, 21); this.number_port.TabIndex = 27; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(13, 55); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(41, 12); this.label2.TabIndex = 26; this.label2.Text = "端口:"; // // txt_password // this.txt_password.Location = new System.Drawing.Point(553, 12); this.txt_password.Name = "txt_password"; this.txt_password.PasswordChar = '*'; this.txt_password.Size = new System.Drawing.Size(211, 21); this.txt_password.TabIndex = 31; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(518, 15); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(41, 12); this.label4.TabIndex = 30; this.label4.Text = "密码:"; // // txt_username // this.txt_username.Location = new System.Drawing.Point(306, 12); this.txt_username.Name = "txt_username"; this.txt_username.Size = new System.Drawing.Size(195, 21); this.txt_username.TabIndex = 29; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(256, 15); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(53, 12); this.label3.TabIndex = 28; this.label3.Text = "用户名:"; // // btn_cancel // this.btn_cancel.Location = new System.Drawing.Point(477, 49); this.btn_cancel.Name = "btn_cancel"; this.btn_cancel.Size = new System.Drawing.Size(73, 21); this.btn_cancel.TabIndex = 34; this.btn_cancel.Text = "取消"; this.btn_cancel.UseVisualStyleBackColor = true; this.btn_cancel.Click += new System.EventHandler(this.btn_cancel_Click_1); // // btn_connect // this.btn_connect.Location = new System.Drawing.Point(383, 49); this.btn_connect.Name = "btn_connect"; this.btn_connect.Size = new System.Drawing.Size(73, 21); this.btn_connect.TabIndex = 33; this.btn_connect.Text = "连接"; this.btn_connect.UseVisualStyleBackColor = true; this.btn_connect.Click += new System.EventHandler(this.btn_connect_Click); // // cb_isSSL // this.cb_isSSL.AutoSize = true; this.cb_isSSL.Location = new System.Drawing.Point(127, 52); this.cb_isSSL.Name = "cb_isSSL"; this.cb_isSSL.Size = new System.Drawing.Size(66, 16); this.cb_isSSL.TabIndex = 32; this.cb_isSSL.Text = "使用SSL"; this.cb_isSSL.UseVisualStyleBackColor = true; this.cb_isSSL.CheckedChanged += new System.EventHandler(this.cb_isSSL_CheckedChanged_1); // // txt_server // this.txt_server.Location = new System.Drawing.Point(61, 12); this.txt_server.Name = "txt_server"; this.txt_server.Size = new System.Drawing.Size(179, 21); this.txt_server.TabIndex = 25; // // skinEngine1 // this.skinEngine1.SerialNumber = ""; this.skinEngine1.SkinFile = null; // // tabPage2 // this.tabPage2.Controls.Add(this.txt_Header); this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Size = new System.Drawing.Size(852, 418); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Header"; this.tabPage2.UseVisualStyleBackColor = true; // // txt_Header // this.txt_Header.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txt_Header.Location = new System.Drawing.Point(6, 3); this.txt_Header.Multiline = true; this.txt_Header.Name = "txt_Header"; this.txt_Header.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.txt_Header.Size = new System.Drawing.Size(841, 550); this.txt_Header.TabIndex = 7; // // Mail // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(904, 644); this.Controls.Add(this.tabControl1); this.Controls.Add(this.label1); this.Controls.Add(this.number_port); this.Controls.Add(this.label2); this.Controls.Add(this.txt_password); this.Controls.Add(this.label4); this.Controls.Add(this.txt_username); this.Controls.Add(this.label3); this.Controls.Add(this.btn_cancel); this.Controls.Add(this.btn_connect); this.Controls.Add(this.cb_isSSL); this.Controls.Add(this.txt_server); this.Name = "Mail"; this.Text = "POP3接收端"; this.Load += new System.EventHandler(this.Mail_Load); this.tabControl1.ResumeLayout(false); this.tabPage1.ResumeLayout(false); this.tabPage1.PerformLayout(); this.toolStrip1.ResumeLayout(false); this.toolStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.number_port)).EndInit(); this.tabPage2.ResumeLayout(false); this.tabPage2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); }#endregionprivate System.Windows.Forms.ToolStripButton delete; private System.Windows.Forms.ToolStripButton save; private System.Windows.Forms.ColumnHeader columnHeader4; private System.Windows.Forms.ColumnHeader columnHeader3; private System.Windows.Forms.ColumnHeader columnHeader2; private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox txt_Body; private System.Windows.Forms.ListView lst_attachment; private System.Windows.Forms.ListView lst_messages; private System.Windows.Forms.ToolStrip toolStrip1; private System.Windows.Forms.Label label1; private System.Windows.Forms.NumericUpDown number_port; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txt_password; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox txt_username; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button btn_cancel; private System.Windows.Forms.Button btn_connect; private System.Windows.Forms.CheckBox cb_isSSL; private System.Windows.Forms.TextBox txt_server; private System.Windows.Forms.ColumnHeader columnHeader5; private System.Windows.Forms.ColumnHeader columnHeader6; private System.Windows.Forms.ColumnHeader columnHeader7; private System.Windows.Forms.ColumnHeader columnHeader10; private System.Windows.Forms.ColumnHeader columnHeader8; private System.Windows.Forms.ColumnHeader columnHeader9; private System.Windows.Forms.ColumnHeader columnHeader11; private System.Windows.Forms.ColumnHeader columnHeader12; private System.Windows.Forms.ColumnHeader columnHeader16; private System.Windows.Forms.ColumnHeader columnHeader17; private Sunisoft.IrisSkin.SkinEngine skinEngine1; private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.TextBox txt_Header; } }

Lumisoft下函数部分属性附表
AcceptLanguage获取或设置邮件发送方请求用于响应的语言。值null表示未指定。AllEntities 获取所有MIME实体作为列表。(继承自MIME_Message。)Attachments 获取此邮件附件。Bcc获取或设置密送收件人邮箱。值null表示未指定。Body获取或设置MIME实体主体。(继承自MIME_Entity。)BodyHtmlText 获取邮件体html文本。如果没有可用的正文html文本,则返回null。BodyText 获取邮件正文文本。如果没有可用的正文,则返回null。BodyTextEncoding 获取邮件正文文本编码。如果没有可用的正文,则返回null。Cc获取或设置抄送收件人邮箱。值null表示未指定。Comments 获取或设置有关邮件的其他注释。值null表示未指定。ContentAlternative 获取或设置邮件替代内容。值null表示标题字段不存在。(继承自MIME_Entity。)ContentBase 获取或设置用于解析此内容部分中的相对URI的基础。值null表示标题字段不存在。(继承自MIME_Entity。)ContentDescription 获取或设置邮件正文部分的描述。值null表示标题字段不存在。在RFC 2045中定义8。(继承自MIME_Entity。)ContentDisposition 获取或设置内容处置。值null表示标题字段不存在。(继承自MIME_Entity。)ContentDuration 获取或设置内容的持续时间。值null表示标题字段不存在。(继承自MIME_Entity。)Contentfeatures 获取或设置MIME正文部分的内容功能。值null表示标题字段不存在。(继承自MIME_Entity。)ContentID 获取或设置内容正文部件ID。值null表示标题字段不存在。在RFC 2045 7中定义。(继承自MIME_Entity。)ContentLanguage 获取或设置邮件内容的语言。值null表示标题字段不存在。(继承自MIME_Entity。)ContentLocation 获取或设置用于检索正文部分的URI。值null表示标题字段不存在。(继承自MIME_Entity。)ContentMD5 获取或设置内容MD5校验和。值null表示标题字段不存在。(继承自MIME_Entity。)ContentTransferEncoding 获取或设置内容传输编码。值null表示标题字段不存在。RFC定义的值在MIME_TransferEncodings中。在RFC 2045中定义6。(继承自MIME_Entity。)ContentType 获取或设置MIME内容类型。值null表示标题字段不存在。在RFC 2045中定义5。(继承自MIME_Entity。)Date获取或设置邮件日期和时间。值DateTime.MinValue表示未指定。DispositionNotificationOptions 获取或设置处置通知选项。值null表示未指定。DispositionNotificationTo 获取或设置邮箱发送处置通知邮件的位置。值null表示未指定。From获取或设置邮件作者。值null表示未指定。Header获取MIME实体头字段集合。(继承自MIME_Entity。)Importance 获取或设置邮件重要性。值null表示未指定。InReplyTo 获取或设置标识已回复的邮件。值null表示未指定。IsDisposed 获取是否释放此对象。(继承自MIME_Entity。)IsModified 获取此实体是否已加载后进行修改。(继承自MIME_Entity。)IsSigned 获取邮件是否包含签名数据。(继承自MIME_Message。)Keywords 获取或设置邮件关键字和/或短语。值null表示未指定。ListArchive 获取或设置邮件列表归档的URL。值null表示未指定。ListHelp 获取或设置邮件列表信息的URL。值null表示未指定。ListID获取或设置邮件列表标识符。值null表示未指定。ListOwner 获取或设置邮件列表所有者邮箱的URL。值null表示未指定。ListPost 获取或设置邮件列表发布的URL。值null表示未指定。ListSubscribe 获取或设置邮件列表订阅的URL。值null表示未指定。ListUnsubscribe 获取或设置邮件列表unsubscription的URL。值null表示未指定。MessageContext 获取或设置邮件的类型或上下文。值null表示未指定。MessageID获取或设置邮件标识符。值null表示未指定。MimeVersion 获取或设置MIME版本号。值null表示标题字段不存在。通常这个值是1.0。在RFC 2045第4节中定义。(继承自MIME_Entity。)OriginalMessageID 获取或设置原始邮件标识符。值null表示未指定。Parent获取此实体的父实体,如果这是根实体,则返回null。(继承自MIME_Entity。)PICSLabel 获取或设置PICS评级标签。值null表示未指定。Priority 获取或设置邮件优先级。值null表示未指定。Received 获取邮件传输跟踪信息。值null表示未指定。References 获取或设置相关的邮件标识符。值null表示未指定。ReplyTo 获取或设置邮箱回复的邮箱。值null表示未指定。ResentBcc 获取或设置重发时邮件被bcc的邮箱。值null表示未指定。ResentCc 获取或设置重新发送邮件的邮箱。值null表示未指定。ResentDate 获取或设置重新发送的日期和时间邮件。值DateTime.MinValue表示未指定。ResentFrom 获取或设置重新发送邮件的人的邮箱。值null表示未指定。ResentMessageID 获取或设置重新发送邮件的邮件标识符。值null表示未指定。ResentReplyTo 获取或设置重新发送的回复。值null表示未指定。ResentSender 获取或设置实际重新发送邮件的人的邮箱。值null表示未指定。ResentTo 获取或设置重新发送邮件的邮箱。值null表示未指定。ReturnPath这样 获取或设置邮件返回路径。值null表示未指定。Sender获取或设置邮件发件人。值null表示未指定。Subject获取或设置邮件主题。值null表示未指定。To获取或设置邮件主要收件人。值null表示未指定。

总结 1、QQ、163、sina等主流邮箱均可以登录。
2、通过解析可以获取邮件的基本信息,比如发件人、邮件正文编码方式、抄送人、主题、大小、时间、ip地址等等。
3、可以执行邮件的删除和下载行为,并可以下载附件,附件的格式没有影响,exe,jpg,pdf均可下载。

    推荐阅读