⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form4.cs

📁 C#写的Email邮件客户端程序skyemail.
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets; 
using System.IO; 
using System.Text;  
using System.Runtime.InteropServices;  
using System.Security.Cryptography;

namespace SkyMail
{
	/// <summary>
	/// Form4 的摘要说明。
	/// </summary>
	public class Form4 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.ToolBar toolBar1;
		private System.Windows.Forms.ToolBarButton toolBarButton1;
		private System.Windows.Forms.ToolBarButton toolBarButton2;
		private System.Windows.Forms.ToolBarButton toolBarButton3;
		private System.Windows.Forms.ToolBarButton toolBarButton4;
		private System.Windows.Forms.ToolBarButton toolBarButton5;
		private System.Windows.Forms.ToolBarButton toolBarButton6;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox textBox5;
		private string CRLF = "\r\n";  
		private string smtplogin = ""; 
		private string smtpserver="";
		private string user="";
		private string pwd="";
		private string emailsddress="";
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;  
		private string	emailaddress="";



		public Form4()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form4));
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.toolBar1 = new System.Windows.Forms.ToolBar();
			this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
			this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
			this.listView1 = new System.Windows.Forms.ListView();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.label4 = new System.Windows.Forms.Label();
			this.textBox5 = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Cursor = System.Windows.Forms.Cursors.Default;
			this.label1.Location = new System.Drawing.Point(16, 52);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "收件人";
			this.label1.Click += new System.EventHandler(this.label1_Click);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 78);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "抄送";
			this.label2.Click += new System.EventHandler(this.label2_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 125);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 23);
			this.label3.TabIndex = 2;
			this.label3.Text = "主题";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(72, 48);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(560, 21);
			this.textBox1.TabIndex = 5;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(72, 72);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(560, 21);
			this.textBox2.TabIndex = 6;
			this.textBox2.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(72, 122);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(560, 21);
			this.textBox3.TabIndex = 7;
			this.textBox3.Text = "";
			// 
			// textBox4
			// 
			this.textBox4.Location = new System.Drawing.Point(8, 150);
			this.textBox4.Multiline = true;
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(624, 304);
			this.textBox4.TabIndex = 8;
			this.textBox4.Text = "";
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// toolBar1
			// 
			this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.toolBarButton1,
																						this.toolBarButton2,
																						this.toolBarButton3,
																						this.toolBarButton4,
																						this.toolBarButton5,
																						this.toolBarButton6});
			this.toolBar1.DropDownArrows = true;
			this.toolBar1.ImageList = this.imageList1;
			this.toolBar1.Name = "toolBar1";
			this.toolBar1.ShowToolTips = true;
			this.toolBar1.Size = new System.Drawing.Size(640, 38);
			this.toolBar1.TabIndex = 9;
			this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
			// 
			// toolBarButton1
			// 
			this.toolBarButton1.ImageIndex = 0;
			this.toolBarButton1.Text = "发送";
			// 
			// toolBarButton2
			// 
			this.toolBarButton2.ImageIndex = 1;
			this.toolBarButton2.Text = "直接发送";
			// 
			// toolBarButton3
			// 
			this.toolBarButton3.ImageIndex = 2;
			this.toolBarButton3.Text = "保存";
			// 
			// toolBarButton4
			// 
			this.toolBarButton4.ImageIndex = 3;
			this.toolBarButton4.Text = "草稿";
			// 
			// toolBarButton5
			// 
			this.toolBarButton5.ImageIndex = 4;
			this.toolBarButton5.Text = "附件";
			// 
			// toolBarButton6
			// 
			this.toolBarButton6.ImageIndex = 5;
			this.toolBarButton6.Text = "地址簿";
			// 
			// listView1
			// 
			this.listView1.ContextMenu = this.contextMenu1;
			this.listView1.Location = new System.Drawing.Point(40, 320);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(112, 88);
			this.listView1.TabIndex = 10;
			this.listView1.View = System.Windows.Forms.View.List;
			this.listView1.Visible = false;
			this.listView1.DoubleClick += new System.EventHandler(this.listView1_DoubleClick);
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																						 this.menuItem1,
																						 this.menuItem2,
																						 this.menuItem3,
																						 this.menuItem4});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "增加附件";
			this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Text = "删除附件";
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 2;
			this.menuItem3.Text = "-";
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 3;
			this.menuItem4.Text = "打开附件";
			this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
			// 
			// label4
			// 
			this.label4.Cursor = System.Windows.Forms.Cursors.Default;
			this.label4.Location = new System.Drawing.Point(16, 103);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(48, 16);
			this.label4.TabIndex = 11;
			this.label4.Text = "暗送";
			this.label4.Click += new System.EventHandler(this.label4_Click);
			// 
			// textBox5
			// 
			this.textBox5.Location = new System.Drawing.Point(72, 97);
			this.textBox5.Name = "textBox5";
			this.textBox5.Size = new System.Drawing.Size(560, 21);
			this.textBox5.TabIndex = 12;
			this.textBox5.Text = "";
			// 
			// Form4
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(640, 469);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.textBox5,
																		  this.label4,
																		  this.listView1,
																		  this.toolBar1,
																		  this.textBox4,
																		  this.textBox3,
																		  this.textBox2,
																		  this.textBox1,
																		  this.label3,
																		  this.label2,
																		  this.label1});
			this.Name = "Form4";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "撰写新邮件";
			this.Load += new System.EventHandler(this.Form4_Load);
			this.ResumeLayout(false);

		}
		#endregion
		private string contect()
		{
			
			DateTime dd=DateTime.Now;
			string  mData="";
			if(listView1.Items.Count<1) ///没有附件的情况
			{
				mData="From:"+emailaddress+ CRLF;
				mData=mData + "Date: "+ dd.ToString() +" +0800"+ CRLF;//日期要指定格式
				mData=mData + "X-Mailer: SkyMail Mailer V1.0" + CRLF;
				mData=mData + "To:" + textBox1.Text  + CRLF;
				string temp="";
				Encoding tmpEncoding = Encoding.ASCII; 
				byte[] binaryData;
				binaryData=Encoding.Default.GetBytes(textBox3.Text);
				temp=Convert.ToBase64String(binaryData, 0,	binaryData.Length);
				mData=mData + "Subject:=?GB2312?B?"+ temp+"?=" + CRLF;
				mData=mData + "Status:U" + CRLF;
				System.Random d2=new System.Random();
				string msgid =dd.Ticks+"." +"skymail" + d2.Next(1000000).ToString(); 
				mData=mData + "Message-Id:" +msgid + CRLF;
				mData=mData + "MIME-Version: 1.0"+ CRLF;
				mData=mData + "Content-Type:multipart/alternative;"+ CRLF;
				mData=mData + " boundary =" + (char)34 + "----=_NextPart_000_000A_01BF9F1A"+(char)34 + CRLF+ CRLF;
				mData=mData + "------=_NextPart_000_000A_01BF9F1A"+ CRLF;
				mData=mData + "Content-Type: text/plain;"+ CRLF;
				mData=mData + "    charset=gb2312"+ CRLF;
				mData=mData + "Content-Transfer-Encoding: base64"+ CRLF+CRLF+CRLF;
				binaryData=Encoding.Default.GetBytes(textBox4.Text);
				temp=Convert.ToBase64String(binaryData, 0,	binaryData.Length);
				mData=mData+ temp +CRLF+CRLF+CRLF;
				
				mData=mData + "------=_NextPart_000_000A_01BF9F1A--"+ CRLF;

			}
			else///需要构造MIME格式邮件
			{
				mData="From:"+emailaddress+ CRLF;
				mData=mData + "Date:" + dd.ToString() +" +0800"+ CRLF;//日期要指定格式
				mData=mData + "X-Mailer: SkyMail Mailer V1.0" + CRLF;
				mData=mData + "To:" + textBox1.Text  + CRLF;
				string temp="";
				Encoding tmpEncoding = Encoding.ASCII; 
				byte[] binaryData;
				binaryData=Encoding.Default.GetBytes(textBox3.Text);
				temp=Convert.ToBase64String(binaryData, 0,	binaryData.Length);
				mData=mData + "Subject:=?GB2312?B?"+ temp+"?=" + CRLF;
				mData=mData + "Status:U" + CRLF;
				mData=mData + "Status:U" + CRLF;
				System.Random d2=new System.Random();
				string msgid =dd.Ticks+"." +"skymail" + d2.Next(1000000).ToString(); 
				mData=mData + "Message-Id:" +msgid + CRLF;
				mData=mData + "MIME-Version: 1.0"+ CRLF;
				mData=mData + "Content-Type:multipart/mixed;"+ CRLF;
				mData=mData + " boundary =" + (char)34 + "----=_NextPart_000_000A_01BF9F1A"+(char)34 + CRLF+ CRLF;
				mData=mData + "------=_NextPart_000_000A_01BF9F1A"+ CRLF;
				mData=mData + "Content-Type: text/plain;charset=gb2312"+ CRLF;
				mData=mData + "Content-Transfer-Encoding: base64"+ CRLF+CRLF+CRLF;
				binaryData=Encoding.Default.GetBytes(textBox4.Text);
				temp=Convert.ToBase64String(binaryData, 0,	binaryData.Length);
				mData=mData+temp+CRLF+CRLF+CRLF;
				int i;
				for(i=0;i<listView1.Items.Count;i++)
				{
					string fnstr;
					fnstr=listView1.Items[i].Text;
					string attstr=base64Encode(fnstr);
					int ends=fnstr.LastIndexOf((char)92);
					fnstr=fnstr.Substring(ends,fnstr.Length-ends );
					string ftemp="";
					Encoding ftmpEncoding = Encoding.ASCII; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -