smtping-email-verifier 1.0.0
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.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +109 -0
- data/lib/smtping/bulk.rb +72 -0
- data/lib/smtping/client.rb +172 -0
- data/lib/smtping/errors.rb +35 -0
- data/lib/smtping/version.rb +6 -0
- data/lib/smtping-email-verifier.rb +4 -0
- data/lib/smtping.rb +51 -0
- metadata +54 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 06ec55ae5ee7c09211c9698dada5ec0c23b998978bbff6209994922bd662bb31
|
|
4
|
+
data.tar.gz: 97145b6b79d1a44cd0d88a4bb9bbeb4081feb67c7b55f9b0582c524498788c28
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 44280978f93634dceab770fdcb023a405d064bb20fa683038dc017cd7d284b45360c3cfc3677837040bc78f96e1b47d49ac19d043d63aa13c2dcc8607566b1a2
|
|
7
|
+
data.tar.gz: 46cb1424056c0d31552abce977ded717ff941c2b8afbd29a0678cfdc2da60da4c91e0be0ef003f91d96257d41f8e24abc80f77dfd75eeac385f8257e7a59c525
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SMTPing
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# SMTPing Email Verifier for Ruby
|
|
2
|
+
|
|
3
|
+
Official Ruby SDK for the [SMTPing](https://smtping.com) email verification API.
|
|
4
|
+
|
|
5
|
+
- Ruby 2.7 or later, no runtime dependencies
|
|
6
|
+
- Automatic retries on rate limits (429) and server errors (5xx)
|
|
7
|
+
- Bulk jobs up to 100,000 addresses, with polling built in
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
gem install smtping-email-verifier
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
or in your Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem "smtping-email-verifier"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Create an API key in the [SMTPing dashboard](https://app.smtping.com). Pass it to the client or set `SMTPING_API_KEY`.
|
|
22
|
+
|
|
23
|
+
## Verify one address
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require "smtping"
|
|
27
|
+
|
|
28
|
+
smtping = Smtping::Client.new # reads SMTPING_API_KEY, or Smtping::Client.new("sk_live_...")
|
|
29
|
+
|
|
30
|
+
r = smtping.verify("jane@example.com")
|
|
31
|
+
puts r["status"], r["band"] # valid, safe
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Every result carries a `band` for simple routing:
|
|
35
|
+
|
|
36
|
+
| band | statuses | action |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `safe` | valid, alias | send |
|
|
39
|
+
| `avoid` | invalid, spamtrap, disposable, blacklisted, complainer, spambot, inbox_full | remove |
|
|
40
|
+
| `judgement` | catch_all, unknown, role and others | your call |
|
|
41
|
+
|
|
42
|
+
## Verify a list
|
|
43
|
+
|
|
44
|
+
Small lists with parallel single calls:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
rows = smtping.verify_many(["a@example.com", "b@example.com"], concurrency: 5)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Large lists as one bulk job:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
job = smtping.bulk.create(emails)
|
|
54
|
+
rows = smtping.bulk.wait(job["jobId"]) { |s| puts s["processedEmails"] }
|
|
55
|
+
|
|
56
|
+
# or in one call
|
|
57
|
+
rows = smtping.bulk.run(emails)
|
|
58
|
+
sendable = rows.select { |x| x["band"] == "safe" }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Check a job later with `bulk.get(job_id)` and `bulk.results(job_id)`.
|
|
62
|
+
|
|
63
|
+
## Threat list checks
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
trap = smtping.check("spamtrap", "jane@example.com")
|
|
67
|
+
puts trap["matched"], trap["source"]
|
|
68
|
+
# also: "disposable", "spambot", "complainer"
|
|
69
|
+
|
|
70
|
+
# up to 1,000 addresses in one call
|
|
71
|
+
batch = smtping.check_batch("disposable", emails)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Credits
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
puts smtping.credits["remaining"]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Errors
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
begin
|
|
84
|
+
smtping.verify("jane@example.com")
|
|
85
|
+
rescue Smtping::InsufficientCreditsError
|
|
86
|
+
# top up
|
|
87
|
+
rescue Smtping::Error => e
|
|
88
|
+
puts e.status, e.message
|
|
89
|
+
end
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Classes: `Smtping::Error` (base, with `status` and `body`), `AuthenticationError`, `InsufficientCreditsError`, `RateLimitError`, `ValidationError`, `JobFailedError`, `TimeoutError`.
|
|
93
|
+
|
|
94
|
+
## Options
|
|
95
|
+
|
|
96
|
+
| option | default | |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| api key (first argument) | `SMTPING_API_KEY` | required |
|
|
99
|
+
| `base_url:` | `https://api.smtping.com/api/v1` | |
|
|
100
|
+
| `timeout:` | `60` | seconds, per request |
|
|
101
|
+
| `max_retries:` | `3` | network errors, 429, 5xx |
|
|
102
|
+
|
|
103
|
+
## Links
|
|
104
|
+
|
|
105
|
+
- [API documentation](https://smtping.com/docs)
|
|
106
|
+
- [Pricing](https://smtping.com/pricing)
|
|
107
|
+
- Support: support@smtping.com
|
|
108
|
+
|
|
109
|
+
MIT License
|
data/lib/smtping/bulk.rb
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Smtping
|
|
4
|
+
# Bulk verification: submit a list, poll the job, fetch the results.
|
|
5
|
+
class Bulk
|
|
6
|
+
def initialize(client)
|
|
7
|
+
@client = client
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Submit up to 100,000 addresses. Duplicates and malformed addresses are removed first.
|
|
11
|
+
def create(emails)
|
|
12
|
+
list = Smtping.normalize(emails, valid_only: true)
|
|
13
|
+
raise ValidationError, "No valid email address in the list" if list.empty?
|
|
14
|
+
raise ValidationError, "A bulk job accepts up to #{BULK_MAX} addresses" if list.size > BULK_MAX
|
|
15
|
+
|
|
16
|
+
job = @client.request(:post, "/verify/bulk", { emails: list }) || {}
|
|
17
|
+
job["totalEmails"] ||= list.size
|
|
18
|
+
job
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get(job_id)
|
|
22
|
+
job = @client.request(:get, "/verify/bulk/#{escape(job_id)}") || {}
|
|
23
|
+
job["jobId"] ||= job_id
|
|
24
|
+
job
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def results(job_id)
|
|
28
|
+
data = @client.request(:get, "/verify/bulk/#{escape(job_id)}/result")
|
|
29
|
+
data = data["results"] if data.is_a?(Hash) && data.key?("results")
|
|
30
|
+
return [] unless data.is_a?(Array)
|
|
31
|
+
|
|
32
|
+
data.map { |r| r.merge("band" => Smtping.band(r["status"])) }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Poll until the job succeeds, then return its results. The block, if any, receives each job status.
|
|
36
|
+
def wait(job_id, timeout: 1800, interval: 5)
|
|
37
|
+
deadline = now + timeout
|
|
38
|
+
delay = interval.to_f
|
|
39
|
+
loop do
|
|
40
|
+
job = get(job_id)
|
|
41
|
+
yield job if block_given?
|
|
42
|
+
status = job["status"].to_s.downcase
|
|
43
|
+
return results(job_id) if status == "succeeded"
|
|
44
|
+
|
|
45
|
+
if %w[failed cancelled].include?(status)
|
|
46
|
+
detail = job["errorMessage"].to_s.empty? ? "" : ": #{job['errorMessage']}"
|
|
47
|
+
raise JobFailedError.new("Job #{job_id} #{status}#{detail}", job)
|
|
48
|
+
end
|
|
49
|
+
raise TimeoutError, "Job #{job_id} still running after #{timeout} s" if now + delay > deadline
|
|
50
|
+
|
|
51
|
+
sleep(delay)
|
|
52
|
+
delay = [delay * 1.5, 30.0].min
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Create a job and wait for its results in one call.
|
|
57
|
+
def run(emails, **options, &block)
|
|
58
|
+
job = create(emails)
|
|
59
|
+
wait(job["jobId"], **options, &block)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def escape(value)
|
|
65
|
+
URI.encode_www_form_component(value.to_s)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def now
|
|
69
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Smtping
|
|
4
|
+
# Client for the SMTPing email verification API.
|
|
5
|
+
class Client
|
|
6
|
+
attr_reader :base_url, :timeout, :max_retries, :user_agent, :bulk
|
|
7
|
+
|
|
8
|
+
NETWORK_ERRORS = [SocketError, SystemCallError, IOError, EOFError, OpenSSL::SSL::SSLError].freeze
|
|
9
|
+
|
|
10
|
+
# api_key defaults to SMTPING_API_KEY. timeout is per request, in seconds.
|
|
11
|
+
def initialize(api_key = nil, base_url: nil, timeout: 60, max_retries: 3, user_agent: nil)
|
|
12
|
+
@api_key = Smtping.first_present(api_key, ENV["SMTPING_API_KEY"])
|
|
13
|
+
raise AuthenticationError, "Missing API key. Pass it to Smtping::Client.new or set SMTPING_API_KEY." unless @api_key
|
|
14
|
+
|
|
15
|
+
@base_url = (Smtping.first_present(base_url, ENV["SMTPING_BASE_URL"]) || DEFAULT_BASE_URL).chomp("/")
|
|
16
|
+
@timeout = timeout
|
|
17
|
+
@max_retries = max_retries
|
|
18
|
+
@user_agent = Smtping.first_present(user_agent) || "smtping-ruby/#{VERSION}"
|
|
19
|
+
@bulk = Bulk.new(self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Verify one address. The result carries a ready-made "band".
|
|
23
|
+
def verify(email)
|
|
24
|
+
e = email.to_s.strip
|
|
25
|
+
raise ValidationError, "Email is required" if e.empty?
|
|
26
|
+
|
|
27
|
+
with_band(request(:post, "/verify/single", { email: e }))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Verify a small list with parallel single calls. Failed addresses come back with status "error".
|
|
31
|
+
def verify_many(emails, concurrency: 5)
|
|
32
|
+
list = Smtping.normalize(emails, valid_only: false)
|
|
33
|
+
results = Array.new(list.size)
|
|
34
|
+
queue = Queue.new
|
|
35
|
+
list.each_with_index { |e, i| queue << [e, i] }
|
|
36
|
+
workers = [[concurrency.to_i, 1].max, [list.size, 1].max].min
|
|
37
|
+
threads = Array.new(workers) do
|
|
38
|
+
Thread.new do
|
|
39
|
+
loop do
|
|
40
|
+
item = begin
|
|
41
|
+
queue.pop(true)
|
|
42
|
+
rescue ThreadError
|
|
43
|
+
nil
|
|
44
|
+
end
|
|
45
|
+
break unless item
|
|
46
|
+
|
|
47
|
+
email, i = item
|
|
48
|
+
results[i] = begin
|
|
49
|
+
verify(email)
|
|
50
|
+
rescue Error => e
|
|
51
|
+
{ "email" => email, "status" => "error", "statusDescription" => e.message, "band" => "judgement" }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
threads.each(&:join)
|
|
57
|
+
results
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Look one address up in a threat list: "spamtrap", "disposable", "spambot" or "complainer".
|
|
61
|
+
def check(type, email)
|
|
62
|
+
t = Smtping.check_type!(type)
|
|
63
|
+
e = email.to_s.strip
|
|
64
|
+
{ "email" => e, "check" => t }.merge(request(:post, "/checks/#{t}", { email: e }) || {})
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Look up to 1,000 addresses up in a threat list in one call.
|
|
68
|
+
def check_batch(type, emails)
|
|
69
|
+
t = Smtping.check_type!(type)
|
|
70
|
+
list = Smtping.normalize(emails, valid_only: true)
|
|
71
|
+
raise ValidationError, "No valid email address in the list" if list.empty?
|
|
72
|
+
raise ValidationError, "A batch check accepts up to #{BATCH_MAX} addresses. Use a job above that." if list.size > BATCH_MAX
|
|
73
|
+
|
|
74
|
+
request(:post, "/checks/#{t}/batch", { emails: list })
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Remaining credit balance.
|
|
78
|
+
def credits
|
|
79
|
+
request(:get, "/credits")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Low-level call to any endpoint. Retries network errors, 429 and 5xx.
|
|
83
|
+
def request(method, path, body = nil)
|
|
84
|
+
uri = URI(@base_url + path)
|
|
85
|
+
payload = body.nil? ? nil : JSON.generate(body)
|
|
86
|
+
attempt = 0
|
|
87
|
+
loop do
|
|
88
|
+
begin
|
|
89
|
+
res = perform(method, uri, payload)
|
|
90
|
+
rescue Net::OpenTimeout, Net::ReadTimeout, *NETWORK_ERRORS => e
|
|
91
|
+
if attempt < @max_retries
|
|
92
|
+
attempt += 1
|
|
93
|
+
sleep(backoff(attempt))
|
|
94
|
+
next
|
|
95
|
+
end
|
|
96
|
+
raise TimeoutError, "Request timed out after #{@timeout} s" if e.is_a?(Net::OpenTimeout) || e.is_a?(Net::ReadTimeout)
|
|
97
|
+
|
|
98
|
+
raise Error, "Network error: #{e.message}"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
status = res.code.to_i
|
|
102
|
+
return parse(res.body) if status.between?(200, 299)
|
|
103
|
+
|
|
104
|
+
if (status == 429 || status >= 500) && attempt < @max_retries
|
|
105
|
+
attempt += 1
|
|
106
|
+
retry_after = res["Retry-After"].to_s.strip
|
|
107
|
+
sleep(retry_after.match?(/\A\d+\z/) && retry_after.to_i.positive? ? retry_after.to_i : backoff(attempt))
|
|
108
|
+
next
|
|
109
|
+
end
|
|
110
|
+
raise error_for(status, res.body)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
def perform(method, uri, payload)
|
|
117
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
118
|
+
http.use_ssl = uri.scheme == "https"
|
|
119
|
+
http.open_timeout = @timeout
|
|
120
|
+
http.read_timeout = @timeout
|
|
121
|
+
http.write_timeout = @timeout if http.respond_to?(:write_timeout=)
|
|
122
|
+
req = (method == :post ? Net::HTTP::Post : Net::HTTP::Get).new(uri.request_uri)
|
|
123
|
+
req["X-API-Key"] = @api_key
|
|
124
|
+
req["Accept"] = "application/json"
|
|
125
|
+
req["User-Agent"] = @user_agent
|
|
126
|
+
if payload
|
|
127
|
+
req["Content-Type"] = "application/json"
|
|
128
|
+
req.body = payload
|
|
129
|
+
end
|
|
130
|
+
http.start { |h| h.request(req) }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def with_band(result)
|
|
134
|
+
r = result.is_a?(Hash) ? result : {}
|
|
135
|
+
r.merge("band" => Smtping.band(r["status"]))
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def parse(text)
|
|
139
|
+
return nil if text.nil? || text.strip.empty?
|
|
140
|
+
|
|
141
|
+
JSON.parse(text)
|
|
142
|
+
rescue JSON::ParserError
|
|
143
|
+
{ "raw" => text }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def error_for(status, body)
|
|
147
|
+
data = begin
|
|
148
|
+
JSON.parse(body.to_s)
|
|
149
|
+
rescue JSON::ParserError
|
|
150
|
+
nil
|
|
151
|
+
end
|
|
152
|
+
message = nil
|
|
153
|
+
if data.is_a?(Hash)
|
|
154
|
+
message = data["error"] if data["error"].is_a?(String)
|
|
155
|
+
message ||= data["message"] if data["message"].is_a?(String)
|
|
156
|
+
end
|
|
157
|
+
message ||= "SMTPing API returned HTTP #{status}"
|
|
158
|
+
klass = case status
|
|
159
|
+
when 401, 403 then AuthenticationError
|
|
160
|
+
when 402 then InsufficientCreditsError
|
|
161
|
+
when 429 then RateLimitError
|
|
162
|
+
when 400, 422 then ValidationError
|
|
163
|
+
else Error
|
|
164
|
+
end
|
|
165
|
+
klass.new(message, status: status, body: body)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def backoff(attempt)
|
|
169
|
+
[2**(attempt - 1), 15].min + (rand * 0.25)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Smtping
|
|
4
|
+
# Base class for every SMTPing error. status is 0 when no HTTP response was received.
|
|
5
|
+
class Error < StandardError
|
|
6
|
+
attr_reader :status, :body
|
|
7
|
+
|
|
8
|
+
def initialize(message = nil, status: 0, body: nil)
|
|
9
|
+
super(message)
|
|
10
|
+
@status = status
|
|
11
|
+
@body = body
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Missing, invalid or revoked API key (401, 403).
|
|
16
|
+
class AuthenticationError < Error; end
|
|
17
|
+
# Not enough credits (402).
|
|
18
|
+
class InsufficientCreditsError < Error; end
|
|
19
|
+
# Rate limit still exceeded after the automatic retries (429).
|
|
20
|
+
class RateLimitError < Error; end
|
|
21
|
+
# Invalid input, rejected locally or by the API (400, 422).
|
|
22
|
+
class ValidationError < Error; end
|
|
23
|
+
# A request or a bulk wait took longer than allowed.
|
|
24
|
+
class TimeoutError < Error; end
|
|
25
|
+
|
|
26
|
+
# A bulk job ended as Failed or Cancelled.
|
|
27
|
+
class JobFailedError < Error
|
|
28
|
+
attr_reader :job
|
|
29
|
+
|
|
30
|
+
def initialize(message, job)
|
|
31
|
+
super(message)
|
|
32
|
+
@job = job
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/smtping.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "uri"
|
|
7
|
+
require_relative "smtping/version"
|
|
8
|
+
require_relative "smtping/errors"
|
|
9
|
+
require_relative "smtping/client"
|
|
10
|
+
require_relative "smtping/bulk"
|
|
11
|
+
|
|
12
|
+
# Official Ruby SDK for the SMTPing email verification API.
|
|
13
|
+
module Smtping
|
|
14
|
+
DEFAULT_BASE_URL = "https://api.smtping.com/api/v1"
|
|
15
|
+
BULK_MAX = 100_000
|
|
16
|
+
BATCH_MAX = 1_000
|
|
17
|
+
CHECKS = %w[spamtrap disposable spambot complainer].freeze
|
|
18
|
+
SAFE = %w[valid alias].freeze
|
|
19
|
+
AVOID = %w[invalid spamtrap disposable blacklisted complainer spambot inbox_full].freeze
|
|
20
|
+
EMAIL_RE = /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/.freeze
|
|
21
|
+
|
|
22
|
+
# "safe" (send), "avoid" (remove) or "judgement" (your call).
|
|
23
|
+
def self.band(status)
|
|
24
|
+
return "safe" if SAFE.include?(status)
|
|
25
|
+
return "avoid" if AVOID.include?(status)
|
|
26
|
+
|
|
27
|
+
"judgement"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.email?(value)
|
|
31
|
+
EMAIL_RE.match?(value.to_s.strip)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.normalize(emails, valid_only:)
|
|
35
|
+
Array(emails).map { |e| e.to_s.strip.downcase }
|
|
36
|
+
.reject(&:empty?)
|
|
37
|
+
.select { |e| !valid_only || email?(e) }
|
|
38
|
+
.uniq
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.check_type!(type)
|
|
42
|
+
t = type.to_s.strip.downcase
|
|
43
|
+
raise ValidationError, "Unknown check \"#{type}\". Use one of: #{CHECKS.join(', ')}" unless CHECKS.include?(t)
|
|
44
|
+
|
|
45
|
+
t
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.first_present(*values)
|
|
49
|
+
values.map { |v| v.to_s.strip }.find { |v| !v.empty? }
|
|
50
|
+
end
|
|
51
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: smtping-email-verifier
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- SMTPing
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Verify one email address or a list of 100,000, flag spamtraps, complainers,
|
|
13
|
+
spambots and disposable addresses. Automatic retries on 429 and 5xx, bulk polling
|
|
14
|
+
built in, no runtime dependencies.
|
|
15
|
+
email: support@smtping.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/smtping-email-verifier.rb
|
|
23
|
+
- lib/smtping.rb
|
|
24
|
+
- lib/smtping/bulk.rb
|
|
25
|
+
- lib/smtping/client.rb
|
|
26
|
+
- lib/smtping/errors.rb
|
|
27
|
+
- lib/smtping/version.rb
|
|
28
|
+
homepage: https://smtping.com/docs#sdks
|
|
29
|
+
licenses:
|
|
30
|
+
- MIT
|
|
31
|
+
metadata:
|
|
32
|
+
homepage_uri: https://smtping.com
|
|
33
|
+
documentation_uri: https://smtping.com/docs#sdks
|
|
34
|
+
source_code_uri: https://github.com/smtping/smtping-ruby
|
|
35
|
+
bug_tracker_uri: https://github.com/smtping/smtping-ruby/issues
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '2.7'
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 4.0.20
|
|
51
|
+
specification_version: 4
|
|
52
|
+
summary: 'SMTPing Email Verifier: official Ruby SDK for the SMTPing email verification
|
|
53
|
+
API'
|
|
54
|
+
test_files: []
|