email_veracity_checker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ README
3
+ Rakefile
4
+ email_veracity_checker.gemspec
5
+ lib/email_check.rb
data/README ADDED
@@ -0,0 +1,25 @@
1
+ Usage
2
+ =====
3
+
4
+ Add following entry in your config/environment.rb
5
+
6
+ config.gem 'email_veracity_checker', :lib => "email_check"
7
+
8
+ How to use:
9
+ #first param is user email address
10
+ #second sender address
11
+ #third param is domain address
12
+
13
+ #Note: It's not sending email, at the end point they quit connection.
14
+
15
+ EmailCheck.run("kiran@joshsoftware.com","no-reply@joshsoftware.com","joshsoftware.com").valid?
16
+
17
+ It's return true or false
18
+
19
+
20
+ Notes
21
+ =====
22
+
23
+ 1) Based on: https://github.com/skillnet/validates_email_with_smtp
24
+
25
+ 2) Not really ideal in production because those mail servers might block you
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('email_veracity_checker', '0.0.1') do |p|
6
+ p.description = "gem that illustrates how to build a gem"
7
+ p.url = "https://github.com/joshsoftware/email_veracity_checke"
8
+ p.author = "Kiran Chaudhari"
9
+ p.email = "kiran@joshsoftware.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{email_veracity_checker}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Kiran Chaudhari"]
9
+ s.date = %q{2010-12-27}
10
+ s.description = %q{gem that illustrates how to build a gem}
11
+ s.email = %q{kiran@joshsoftware.com}
12
+ s.extra_rdoc_files = ["README", "lib/email_check.rb"]
13
+ s.files = ["Manifest", "README", "Rakefile", "email_veracity_checker.gemspec", "lib/email_check.rb"]
14
+ s.homepage = %q{https://github.com/joshsoftware/email_veracity_checke}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Email_veracity_checker", "--main", "README"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{email_veracity_checker}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{gem that illustrates how to build a gem}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,125 @@
1
+ require 'resolv'
2
+ require 'net/smtp'
3
+
4
+ class EmailCheck < Net::SMTP
5
+
6
+ class EmailCheckStatus
7
+ attr_accessor :errors
8
+
9
+ def self.rcpt_responses
10
+ @@rcpt_responses ||=
11
+ {
12
+ -1 => :fail, # Validation failed (non-SMTP)
13
+ 250 => :valid, # Requested mail action okay, completed
14
+ 251 => :dunno, # User not local; will forward to <forward-path>
15
+ 550 => :invalid, # Requested action not taken:, mailbox unavailable
16
+ 551 => :dunno, # User not local; please try <forward-path>
17
+ 552 => :valid, # Requested mail action aborted:, exceeded storage allocation
18
+ 553 => :invalid, # Requested action not taken:, mailbox name not allowed
19
+ 450 => :valid_fails, # Requested mail action not taken:, mailbox unavailable
20
+ 451 => :valid_fails, # Requested action aborted:, local error in processing
21
+ 452 => :valid_fails, # Requested action not taken:, insufficient system storage
22
+ 500 => :fail, # Syntax error, command unrecognised
23
+ 501 => :invalid, # Syntax error in parameters or arguments
24
+ 503 => :fail, # Bad sequence of commands
25
+ 550 => :fail, # Unknown user
26
+ 521 => :invalid, # <domain> does not accept mail [rfc1846]
27
+ 421 => :fail, # <domain> Service not available, closing transmission channel
28
+ }
29
+ end
30
+
31
+ def initialize(response_code, error = nil)
32
+ errors = Array.new
33
+ errors.push error unless error.nil?
34
+ @response = (self.class.rcpt_responses.has_key?(response_code) ?
35
+ response_code : -1)
36
+ end
37
+
38
+ # Symbolic status of mail address verification.
39
+ #
40
+ # :fail Verification failed
41
+ # :dunno Verification succeeded, but can't tell about validity
42
+ # :valid address known to be valid
43
+ # :valid_fails address known to be valid, delivery would have failed temporarily
44
+ # :invalid address known to be invalid
45
+ def status
46
+ @@rcpt_responses[@response]
47
+ end
48
+
49
+ # true if verified address is known to be valid
50
+ def valid?
51
+ [:valid, :valid_fails].include? self.status
52
+ #puts "[CHECK EMAIL EXISTS] status is #{self.status}."
53
+ end
54
+
55
+ # true if verified address is known to be invalid
56
+ def invalid?
57
+ self.status == :invalid
58
+ end
59
+ end
60
+
61
+ #decoy_from = "development@einsteinindustries.com"
62
+ #domain = "einsteinindustries.com"
63
+ #call EmailCheck.run(email, decoy_from, domain, server = nil )
64
+ def self.run(addr, decoy_from, domain, server = nil)
65
+ if addr.index('@').nil?
66
+ ret = EmailCheckStatus.new(-1, error)
67
+ #puts "[CHECK EMAIL EXISTS] email is #{addr} -> no email specified"
68
+ return ret
69
+ end
70
+
71
+ server = get_mail_server(addr[(addr.index('@')+1)..-1]) if server.nil?
72
+ ret = nil
73
+
74
+ #puts "[CHECK EMAIL EXISTS] email is #{addr}."
75
+ #puts "[CHECK EMAIL EXISTS] addr is #{server}."
76
+
77
+ begin
78
+ smtp = EmailCheck.new(server)
79
+ smtp.set_debug_output $stderr
80
+ smtp.start(domain)
81
+ ret = smtp.check_mail_addr(domain, addr, decoy_from)
82
+ smtp.finish
83
+
84
+ if ret.class != String
85
+ # ruby 1.8.7
86
+ #puts "[CHECK EMAIL EXISTS] ret success is #{ret.success?}."
87
+ #puts "[CHECK EMAIL EXISTS] ret message is #{ret.message}."
88
+ #puts "[CHECK EMAIL EXISTS] ret status is #{ret.status}."
89
+ ret = EmailCheckStatus.new(ret.message.to_s[0..2].to_i)
90
+ else
91
+ # ruby 1.8.5
92
+ ret = EmailCheckStatus.new(ret[0..2].to_i)
93
+ end
94
+ rescue Net::SMTPAuthenticationError, Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => error
95
+ ret = EmailCheckStatus.new(error.to_s[0..2].to_i, error)
96
+ #puts "[CHECK EMAIL EXISTS] ret1 is #{ret}, error is #{error.to_s[0..2]}."
97
+ rescue IOError, TimeoutError, ArgumentError => error
98
+ ret = EmailCheckStatus.new(-1, error)
99
+ #puts "[CHECK EMAIL EXISTS] ret2 is #{ret}, error is #{error}."
100
+ rescue Exception => error
101
+ ret = EmailCheckStatus.new(-1, error)
102
+ #puts "[CHECK EMAIL EXISTS] ret3 is #{ret}, error is #{error}."
103
+ end
104
+
105
+ return ret
106
+ end
107
+
108
+ def check_mail_addr(domain, to_addr, decoy_from = nil)
109
+ raise IOError, 'closed session' unless @socket
110
+ raise ArgumentError, 'mail destination not given' if to_addr.empty?
111
+ helo domain
112
+ mailfrom decoy_from
113
+ rcptto to_addr
114
+ end
115
+
116
+ # Gets the MX record
117
+ # Note: might need to add other records if mx is insufficient
118
+ def self.get_mail_server(host)
119
+ res = Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::MX)
120
+ unless res.empty?
121
+ return res.sort {|x,y| x.preference <=> y.preference}.first.exchange.to_s
122
+ end
123
+ nil
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_veracity_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kiran Chaudhari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-12-27 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: gem that illustrates how to build a gem
17
+ email: kiran@joshsoftware.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - lib/email_check.rb
25
+ files:
26
+ - Manifest
27
+ - README
28
+ - Rakefile
29
+ - email_veracity_checker.gemspec
30
+ - lib/email_check.rb
31
+ has_rdoc: true
32
+ homepage: https://github.com/joshsoftware/email_veracity_checke
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --line-numbers
38
+ - --inline-source
39
+ - --title
40
+ - Email_veracity_checker
41
+ - --main
42
+ - README
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "1.2"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: email_veracity_checker
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: gem that illustrates how to build a gem
64
+ test_files: []
65
+