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

📄 emailsender.cs

📁 工资结算系统 拥有权限控制 临时工资表 自动导入导出Excel 以及邮件群发功能
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(336, 296);
			this.groupBox3.TabIndex = 12;
			this.groupBox3.TabStop = false;
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(56, 144);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(48, 23);
			this.label8.TabIndex = 18;
			this.label8.Text = "密码:";
			// 
			// textBox6
			// 
			this.textBox6.Location = new System.Drawing.Point(104, 144);
			this.textBox6.Name = "textBox6";
			this.textBox6.PasswordChar = '*';
			this.textBox6.Size = new System.Drawing.Size(160, 21);
			this.textBox6.TabIndex = 17;
			this.textBox6.Text = "";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(40, 200);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 23);
			this.label7.TabIndex = 16;
			this.label7.Text = "用户名:";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(24, 88);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 23);
			this.label6.TabIndex = 15;
			this.label6.Text = "发件人邮箱:";
			// 
			// textBox5
			// 
			this.textBox5.Location = new System.Drawing.Point(104, 200);
			this.textBox5.Name = "textBox5";
			this.textBox5.Size = new System.Drawing.Size(160, 21);
			this.textBox5.TabIndex = 14;
			this.textBox5.Text = "";
			// 
			// textBox4
			// 
			this.textBox4.Location = new System.Drawing.Point(104, 88);
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(160, 21);
			this.textBox4.TabIndex = 13;
			this.textBox4.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(24, 32);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 23);
			this.label5.TabIndex = 12;
			this.label5.Text = "SMTP服务器:";
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(104, 32);
			this.textBox3.Name = "textBox3";
			this.textBox3.ReadOnly = true;
			this.textBox3.Size = new System.Drawing.Size(160, 21);
			this.textBox3.TabIndex = 11;
			this.textBox3.Text = "";
			// 
			// button3
			// 
			this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button3.Location = new System.Drawing.Point(264, 32);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(64, 23);
			this.button3.TabIndex = 10;
			this.button3.Text = "修改";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// EmailSender
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.MintCream;
			this.ClientSize = new System.Drawing.Size(760, 534);
			this.Controls.Add(this.richTextBox2);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.groupBox1);
			this.Name = "EmailSender";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Email发送信息框";
			this.Load += new System.EventHandler(this.EmailSender_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		
		private void EmailSender_Load(object sender, System.EventArgs e)
		{
			SmtpUtil smtputil=new SmtpUtil();
			textBox1_Load();


			this.emlsmtpserver=smtputil.getSMTPSERVER();
			this.emlfrom=smtputil.getFROM();
			this.emla_username=smtputil.geta_userNAME();
			this.emlpassword=smtputil.getPASSWORD();
			this.textBox3.Text=this.emlsmtpserver;
			this.textBox4.Text=this.emlfrom;
			this.textBox5.Text=this.emla_username;
			this.textBox6.Text=this.emlpassword;
			
			
		}
		private void textBox1_Load()
		{
			string  emlstring="";
			int num=this.eml.Count-1;
			int i=0;
			for(i=0;i<num;i++)
			{
				
				emlstring+=(this.eml[i].ToString())+",";
				
			}
			if(i==num) emlstring+=(this.eml[i].ToString());
			this.textBox1.Text=emlstring;

		}
		
		private void button2_Click(object sender, System.EventArgs e)
		{
			
						
			this.Close();
		}
		private string sender_Check()
		{
			string error="";
			if(this.textBox4.Text=="" || this.textBox4.Text.Trim().Equals(""))
			{
				error="发件人邮箱不能为空!!!\n     请重新更新\n  ";
				return error;
			}
			if((this.textBox4.Text.IndexOf("@")==-1) || (this.textBox4.Text.IndexOf(".")==-1))
			{
				error+="发件人邮箱格式不正确!!!\n     请重新更新\n  ";
				return error;
			}
			return error;			
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			string  error="";
			error=sender_Check();
			
			if(error!="")
			{
				MessageBox.Show(error);
				return;
			}
			
			if(!this.textBox3.Text.Equals(this.emlsmtpserver))
			{
				error+="SMTP服务器已更新\n ";
				
			}
			if(!this.textBox4.Text.Equals(this.emlfrom))
			{
				error+="发件人邮箱已更新\n";
				
			}
			if(!this.textBox6.Text.Equals(this.emlpassword))
			{
				error+="密码已更新\n";
				
			}
			if(this.textBox6.Text=="")
			{
				error+="密码为空\n";
				
			}
			if(MessageBox.Show (error+"\n\n              您确认信息正确吗?\n  若信息有误,在您发送后,将不能成功发信! 确实要发送吗?", "提示信息框",MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.No)  return;
            
			int num=((DataSet)(this.dg.DataSource)).Tables[0].Rows.Count;
		
			int num1=((DataSet)(this.dg.DataSource)).Tables[0].Columns.Count;
			//bool  senderflag=true;
			
			int i=0;
			for(i=1;i<num;i++)
			{
			if(this.dg.IsSelected(i))
				{ 
				SmtpUtil smtputil=new SmtpUtil(this.textBox4.Text,this.textBox3.Text,this.textBox6.Text);
					
					string  mess=this.richTextBox2.Text;
					 mess= mess.Replace("\n","<br>");
					int j=0;

					string  text="<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">";
					text+="<tr> <td><font color=\"#000080\">"+this.dg[i,1].ToString()+",您好!</font><p> </td></tr>";
					text+="<tr><td><font color=\"#000080\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+mess+"<span lang=\"zh-cn\"> </span></font><br><p></td> </tr> <caption> </caption></tr></table>";
					text+="<p><font color=\"#000080\"><span lang=\"zh-cn\"> &nbsp;&nbsp; </span></font></p>";
					text+="	<table cellSpacing=\"0\" cellPadding=\"0\" width=\"200%\" border=\"2\" style=\"border-collapse: collapse\" bordercolor=\"#008080\" bgcolor=\"#FFFFCC\">";
 
					text+="<td width=\"75\"><p align=\"left\"><font color=\"#000000\">"+this.dg[0,0].ToString()+"</font></td>";
					text+="<td width=\"100\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[0,1].ToString()+" </font></td>";
					text+="<td width=\"200\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[0,2].ToString()+" </font></td>";
					text+="<td width=\"100\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[0,3].ToString()+" </font></td>";
					
					if(num1>4)
					{
						for(j=4;j<num1;j++)
						{
							text+="<td width=\"75\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[0,j].ToString()+"</font> </td>";
						}
					}
					text+="</tr><tr>";

					text+="<td width=\"75\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[i,0].ToString()+"</font> </td>";
					text+="<td width=\"100\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[i,1].ToString()+" </font></td>";
					text+="<td width=\"200\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[i,2].ToString()+"</font> </td>";
					text+="<td width=\"100\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[i,3].ToString()+"</font> </td>";
	
					if(num1>4)
					{
						for(j=4;j<num1;j++)
						{
							text+="<td width=\"75\"> <p align=\"left\"><font color=\"#000000\">"+this.dg[i,j].ToString()+"</font> </td>";
						}
					}
					text+="</tr></table><p></p>";
					text+="<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">";
					text+="<br><br><br><p><span lang=\"zh-cn\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
					text+="</span>&nbsp;<font color=\"#000080\">发件人:"+this.textBox5.Text+" </font></p>";
					text+="<p><font color=\"#000080\"><span lang=\"zh-cn\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
					text+="</span>&nbsp;&nbsp; </font><span lang=\"zh-cn\"><font color=\"#000080\">&nbsp;时间:&nbsp;"; 
					text+=System.DateTime.Now.ToShortDateString()+" </font>&nbsp;&nbsp;&nbsp; </span>";
					text+=" </td></tr></table>";
				
				try
					{
						
						smtputil.sendHtmlMailNoHeadTail(this.dg[i,2].ToString(),this.textBox2.Text,text);//thisemailstring"okokokkkdd\n");////);//"");
					}
					catch(Exception ee)
					{
						//senderflag=false;
						MessageBox.Show("邮件发送失败!!!\n\n  请检查SMTP服务器,发件人邮箱,密码,用户名信息\n   若上述信息无误,请参看下述信息:\n"+ee.ToString());
						
						break;
					}

				}

			}
			if(i>=num)//senderflag)
			{
					MessageBox.Show("邮件已发送!");
					
				   this.Close();
			}
		}
		public void setParameter(string  textbox3text)
		{
			this.textBox3.Text=textbox3text;
		}
	

		private void button3_Click(object sender, System.EventArgs e)
		{
			salary.SmtpserverModify smtpservermodify=new salary.SmtpserverModify(this.textBox3.Text);
			smtpservermodify.Owner=this;
			smtpservermodify.ShowDialog();
		}
	
	}
}

⌨️ 快捷键说明

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