Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'mailgun'
  4. require 'pp'
  5.  
  6. api_key = ARGV[0]
  7.  
  8. raise "no api key" if api_key.nil?
  9.  
  10. data = DATA.read
  11. emails = data.split("\n")
  12.  
  13. puts "Emails size: #{emails.size}"
  14. puts "Emails uniq size: #{emails.uniq.size}\n"
  15.  
  16. emails.uniq.each_with_index do |email, index|
  17. mg_obj = Mailgun::Address.new(api_key)
  18. res = mg_obj.validate(email)
  19.  
  20. unless res["is_valid"]
  21. puts "\nInvalid email address #{email}:"
  22. pp res
  23. else
  24. print "."
  25. end
  26.  
  27. # # Example response:
  28. # {
  29. # "address" => "alice@mailgun.net",
  30. # "did_you_mean" => nil,
  31. # "is_valid" => true,
  32. # "parts" => {
  33. # "display_name" => nil,
  34. # "domain" => "mailgun.net",
  35. # "local_part" => "alice",
  36. # },
  37. # }
  38. end
  39.  
  40. puts "\nDone"
  41.  
  42. __END__
  43. new line separated list of emails goes here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement