Advertisement
Guest User

Untitled

a guest
Apr 10th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.94 KB | None | 0 0
  1. let CheckHost email =
  2.     let addr = new System.Net.Mail.MailAddress(email)
  3.     let res = ActiveUp.Net.Mail.Validator.GetMxRecords(addr.Host)
  4.     if res <> null then Some(res) else None
  5.  
  6. [<EntryPoint>]
  7. let main argv =
  8.     let emailValidator = (new System.ComponentModel.DataAnnotations.EmailAddressAttribute()).IsValid
  9.     let validEmails = System.IO.File.ReadAllLines(argv.[0]) |> Seq.filter emailValidator
  10.     System.IO.File.WriteAllLines(argv.[0] + "_out.txt", validEmails)
  11.     let checkedEmails = validEmails |> Seq.map (fun e -> match CheckHost e with |Some res -> (e, res.Count) | None -> (e, 0))
  12.     let badCount = checkedEmails |> Seq.filter (fun (e,c) -> c = 0) |> Seq.length
  13.     printfn "%d bad emails" badCount
  14.     System.IO.File.WriteAllLines(argv.[0] + "_out2.txt", validEmails)
  15.     printfn "%f bad emails" (float(badCount) / float(Seq.length checkedEmails))
  16.     System.Console.ReadLine() |> ignore
  17.     0 // return an integer exit codes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement