private void _bFilterEmails_Click(object sender, EventArgs e) { // We instantiate the pop3 client. Pop3Client pop = new Pop3Client(); try { this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text)); // Connect to the pop3 client pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text); AddressCollection ac; HeaderCollection hc = new HeaderCollection(); //Retrive a message headers for (int n = 1; n < pop.MessageCount + 1; n++) { Header h = pop.RetrieveHeaderObject(n); ac = new AddressCollection(); ac.Add(h.From); ac = SmtpValidator.Filter(ac); //If address is not filtered if (ac.Count > 0) { hc.Add(h); } } this.AddLogEntry(string.Format(" {0} messages passed the filter", hc.Count.ToString())); } catch (Pop3Exception pexp) { this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message)); } catch (Exception ex) { this.AddLogEntry(string.Format("Failed: {0}", ex.Message)); } finally { if (pop.IsConnected) { pop.Disconnect(); } } }
private void _bValidateEmail_Click(object sender, EventArgs e) { bool result = false; if (_cbUseDnsToValidateEmail.Checked && _tbDnsServer.Text != string.Empty) { result = SmtpValidator.Validate(_tbEmail.Text, _tbDnsServer.Text); } else { result = SmtpValidator.Validate(_tbEmail.Text); } if (result) { this.AddLogEntry("Valid Email address"); } else { this.AddLogEntry("Invalid Email address"); } }