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

📄 sendmailform.cs

📁 点对点通信的资料 是论文加程序性质的 计算机网络方向的
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.menuItem15.Index = 0;
			this.menuItem15.Text = "大图标";
			this.menuItem15.Click += new System.EventHandler(this.menuItem15_Click_1);
			// 
			// menuItem17
			// 
			this.menuItem17.Index = 1;
			this.menuItem17.Text = "小图标";
			this.menuItem17.Click += new System.EventHandler(this.menuItem17_Click);
			// 
			// menuItem16
			// 
			this.menuItem16.Index = 2;
			this.menuItem16.Text = "列表";
			this.menuItem16.Click += new System.EventHandler(this.menuItem16_Click_1);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.cbHtml);
			this.groupBox2.Controls.Add(this.txtTo);
			this.groupBox2.Controls.Add(this.label3);
			this.groupBox2.Controls.Add(this.label4);
			this.groupBox2.Controls.Add(this.txtSubject);
			this.groupBox2.Dock = System.Windows.Forms.DockStyle.Top;
			this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox2.Location = new System.Drawing.Point(0, 41);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(800, 104);
			this.groupBox2.TabIndex = 4;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "邮件头";
			// 
			// cbHtml
			// 
			this.cbHtml.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.cbHtml.Items.AddRange(new object[] {
														"HTML邮件",
														"纯文本邮件"});
			this.cbHtml.Location = new System.Drawing.Point(704, 72);
			this.cbHtml.Name = "cbHtml";
			this.cbHtml.Size = new System.Drawing.Size(88, 20);
			this.cbHtml.TabIndex = 8;
			this.cbHtml.Text = "HTML邮件";
			// 
			// txtTo
			// 
			this.txtTo.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.txtTo.Location = new System.Drawing.Point(88, 72);
			this.txtTo.Name = "txtTo";
			this.txtTo.Size = new System.Drawing.Size(584, 21);
			this.txtTo.TabIndex = 6;
			this.txtTo.Text = "yinhu82@163.com,yinhu82@sina.com.cn";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(48, 23);
			this.label3.TabIndex = 5;
			this.label3.Text = "收件人:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 32);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 23);
			this.label4.TabIndex = 4;
			this.label4.Text = "邮件主题:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txtSubject
			// 
			this.txtSubject.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.txtSubject.Location = new System.Drawing.Point(88, 32);
			this.txtSubject.Name = "txtSubject";
			this.txtSubject.Size = new System.Drawing.Size(664, 21);
			this.txtSubject.TabIndex = 7;
			this.txtSubject.Text = "最新版";
			// 
			// ltAttachment
			// 
			this.ltAttachment.AllowDrop = true;
			this.ltAttachment.ContextMenu = this.conAttachment;
			this.ltAttachment.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.ltAttachment.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
			this.ltAttachment.LargeImageList = this.imlAttachment;
			this.ltAttachment.Location = new System.Drawing.Point(0, 392);
			this.ltAttachment.Name = "ltAttachment";
			this.ltAttachment.Size = new System.Drawing.Size(800, 97);
			this.ltAttachment.TabIndex = 5;
			this.ltAttachment.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView1_DragDrop);
			this.ltAttachment.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter);
			// 
			// splitter1
			// 
			this.splitter1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter1.Location = new System.Drawing.Point(0, 388);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(800, 4);
			this.splitter1.TabIndex = 6;
			this.splitter1.TabStop = false;
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.txtMessage);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel1.Location = new System.Drawing.Point(0, 145);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(800, 243);
			this.panel1.TabIndex = 7;
			// 
			// txtMessage
			// 
			this.txtMessage.Dock = System.Windows.Forms.DockStyle.Fill;
			this.txtMessage.Location = new System.Drawing.Point(0, 0);
			this.txtMessage.Name = "txtMessage";
			this.txtMessage.Size = new System.Drawing.Size(800, 243);
			this.txtMessage.TabIndex = 0;
			this.txtMessage.Text = "呵呵 这是第一封试验邮件";
			// 
			// SendMailForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(800, 489);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.ltAttachment);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.toolBar1);
			this.Menu = this.mainMenu1;
			this.Name = "SendMailForm";
			this.Text = "Send";
			this.Load += new System.EventHandler(this.SendMailForm_Load);
			this.groupBox2.ResumeLayout(false);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion


		//发送邮件
		private void menuItem2_Click(object sender, System.EventArgs e)
		{
			bool html=false;
			if(this.cbHtml .Text=="HTML邮件"|this.cbHtml .Text =="纯文本邮件")
			{
				if(this.cbHtml .Text=="HTML邮件")
					html=true;
				else if(this.cbHtml .Text=="纯文本邮件")
					html=false;
			}
			else 
			{
				MessageBox.Show ("请做出有效的邮件格式选择");
				this.cbHtml .Text ="HTML邮件";
				return;
			}
				
			SmtpMail send=new SmtpMail (array);
			Cursor.Current =Cursors.WaitCursor ;
			send.Charset ="GB2312";
			send.Priority ="Normal";
			send.eSmtp=true;
			send.MailServerUserName =SystemManage.UserName ;
			send.MailServerPassWord =SystemManage.PassWd ;
			send.Send (SystemManage.SmtpName,SystemManage.MailAddress ,SystemManage.AccountName,this.txtTo .Text ,html,this.txtSubject .Text ,this.txtMessage .Text );
			Cursor.Current =Cursors.Default ;
			SystemManage.letterNumber ++;
			ltAttachment  .Items .Clear ();
			this.Close ();
		}
		
	

		private void menuItem4_Click(object sender, System.EventArgs e)
		{
			this.Close ();
		}

		//添加附件名称和图标的函数
		private void btnAdd_Click()
		{

			if(this.openFileDialog1 .ShowDialog()==DialogResult.OK)
			{
				array.Add (this.openFileDialog1 .FileName );
				AddIcon(this.openFileDialog1.FileName);
				ltAttachment  .Visible =true;
				this.splitter1 .Visible =true;
			}
		}


		
		/// <summary>
		/// 判断加入的文件格式,并添加到附件ListView中
		/// </summary>
		/// <param name="fileType"></param>
		private void AddIcon(string fileType)
		{
			//string type = fileType.Substring(fileType.Length - 3);
			try 
			{
				string Name = fileType.Substring(fileType.LastIndexOf(@"\") + 1);
				this.imlAttachment.Images.Add(GetIcon(fileType));
				this.ltAttachment.LargeImageList = this.imlAttachment;
				this.ltAttachment .SmallImageList =this.imlAttachment ;
				this.ltAttachment .Items .Add (Name,i++);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString ());
			}
		}

			

			
		
			
			

		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			switch(this.toolBar1 .Buttons.IndexOf (e.Button ))
			{
				case 0:
					menuItem2_Click(null,null);
					break;
				case 1:
					this.saveFileDialog1.Title ="保存信件";
					this.saveFileDialog1 .Filter ="文本文件(*.txt)|*.txt|All Files(*.*)|*.*";
					AddExtra extra=new AddExtra( array);
					string info="SMTP地址:"+SystemManage.SmtpName+"\r\n用户名:"+SystemManage.UserName+"\r\n密码:"+SystemManage.PassWd+"\r\n发信人地址:"+SystemManage.MailAddress+"\r\n主题:"+this.txtSubject .Text+"\r\n收信人地址:"+this.txtTo .Text +"\r\n信件内容:"+this.txtMessage .Text+"\r\n";
					if(this.saveFileDialog1 .ShowDialog ()==DialogResult.OK )
					{
						extra.SaveLetter (this.saveFileDialog1 .FileName,info);
						MessageBox.Show ("信件保存成功!");
					}
					break;
				
				case 3:
					btnAdd_Click();
					break;
				
				default:
				
					MessageBox.Show ("此功能还没有完善");
					break;
				
			}
		}

		private void menuItem7_Click(object sender, System.EventArgs e)
		{
			btnAdd_Click();
		}

		private void SendMailForm_Load(object sender, System.EventArgs e)
		{
			ltAttachment  .Visible =false;
			this.splitter1 .Visible =false;
		}



		//附件的"删除"操作
		private void menuItem10_Click(object sender, System.EventArgs e)
		{
			try
			{
				if(ltAttachment  .Items .Count >1)
				{
					//因为在添加一个附件的时候,刚好也是添加了一个ListView中的文件名
					//所以他们的索引值是相同的。所以可以通过选中的ListView的索引值来删除附件
					array.RemoveAt (ltAttachment.SelectedItems [0].Index );
					ltAttachment .Items .RemoveAt (ltAttachment  .SelectedIndices[0] );
				}
				else if(ltAttachment  .Items .Count ==1)
		
				{
					array.RemoveAt(ltAttachment .SelectedItems [0].Index);
					ltAttachment .Items .RemoveAt (ltAttachment  .SelectedIndices[0] );
					this.splitter1 .Visible =false;
					ltAttachment  .Visible =false;
				}	
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
			}
		}

		private void menuItem9_Click_1(object sender, System.EventArgs e)
		{
			btnAdd_Click();
		
		}

		private void menuItem15_Click_1(object sender, System.EventArgs e)
		{
			ltAttachment  .View =View.LargeIcon ;
		}

		private void menuItem17_Click(object sender, System.EventArgs e)
		{
			ltAttachment  .View =View.SmallIcon ;
		
		}

		private void menuItem16_Click_1(object sender, System.EventArgs e)
		{
			ltAttachment  .View =View.List;
		}

		
		//"打开"操作
		private void menuItem12_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (this.ltAttachment.SelectedItems[0].ToString() != "")
				{
					int length = this.ltAttachment.SelectedItems[0].ToString().Length;
					string ss = this.ltAttachment.SelectedItems[0].ToString().Substring(15, length - 16);
					ShellExecute(IntPtr.Zero, "Open", ss, null, null, 0);
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
			}
		}
				
				
			
		
		//以下的两个事件是用来支持在添加附件时候的拖放操作的
		private void listView1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
		{
			try
			{
				if (e.Data.GetDataPresent(DataFormats.FileDrop))
				{
					string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

				
					for (int i = 0; i < files.Length; i++)
					{
						array.Add(files[i]);
						AddIcon(files[i]);
					}
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
			}
			
		
		}

		private void listView1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
		{
			try
			{
				if (e.Data.GetDataPresent(DataFormats.FileDrop))
					e.Effect = DragDropEffects.Copy;
				else
					e.Effect = DragDropEffects.None;
			}
			catch(Exception ex)
			{
				MessageBox.Show (ex.ToString ());
			}
		
		}

	}
}

⌨️ 快捷键说明

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