-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/smtp retry if one mx found (#24)
* Implement SMTP retry * Update gem documentation * Refactor * Update gem version
- Loading branch information
Showing
14 changed files
with
182 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
truemail (0.1.4) | ||
truemail (0.1.5) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,8 +64,10 @@ Truemail.configure do |config| | |
# Optional parameter. A SMTP server response timeout is equal to 2 ms by default. | ||
config.response_timeout = 1 | ||
|
||
# Optional parameter. Total of timeout retry. It is equal to 1 by default. | ||
config.retry_count = 2 | ||
# Optional parameter. Total of connection attempts. It is equal to 2 by default. | ||
# This parameter uses in mx lookup timeout error and smtp request (for cases when | ||
# there is one mx server). | ||
config.connection_attempts = 3 | ||
|
||
# Optional parameter. You can predefine which type of validation will be used for domains. | ||
# Available validation types: :regex, :mx, :smtp | ||
|
@@ -91,7 +93,7 @@ Truemail.configuration | |
@connection_timeout=1, | ||
@email_pattern=/regex_pattern/, | ||
@response_timeout=1, | ||
@retry_count=2, | ||
@connection_attempts=3, | ||
@validation_type_by_domain={}, | ||
@verifier_domain="somedomain.com", | ||
@verifier_email="[email protected]" | ||
|
@@ -105,15 +107,15 @@ Truemail.configuration.connection_timeout = 3 | |
=> 3 | ||
Truemail.configuration.response_timeout = 4 | ||
=> 4 | ||
Truemail.configuration.retry_count = 1 | ||
Truemail.configuration.connection_attempts = 1 | ||
=> 1 | ||
|
||
Truemail.configuration | ||
=> #<Truemail::Configuration:0x000055590cb17b40 | ||
@connection_timeout=3, | ||
@email_pattern=/regex_pattern/, | ||
@response_timeout=4, | ||
@retry_count=1, | ||
@connection_attempts=1, | ||
@validation_type_by_domain={}, | ||
@verifier_domain="somedomain.com", | ||
@verifier_email="[email protected]", | ||
|
@@ -187,7 +189,13 @@ Truemail.validate('[email protected]', with: :regex) | |
|
||
#### MX validation | ||
|
||
Validation by MX records is the second validation level. It uses Regex validation before running itself. When regex validation has completed successfully then runs itself. Truemail MX validation performs strictly following the [RFC 5321](https://tools.ietf.org/html/rfc5321#section-5) standard. | ||
Validation by MX records is the second validation level. It uses Regex validation before running itself. When regex validation has completed successfully then runs itself. | ||
|
||
```code | ||
[Regex validation] -> [MX validation] | ||
``` | ||
|
||
Truemail MX validation performs strictly following the [RFC 5321](https://tools.ietf.org/html/rfc5321#section-5) standard. | ||
|
||
Example of usage: | ||
|
||
|
@@ -206,7 +214,7 @@ Truemail.validate('[email protected]', with: :mx) | |
success=true, | ||
email="[email protected]", | ||
domain="example.com", | ||
mail_servers=["mx1.example.com", "mx2.example.com"], | ||
mail_servers=["127.0.1.1", "127.0.1.2"], | ||
errors={}, | ||
smtp_debug=nil>, | ||
@validation_type=:mx> | ||
|
@@ -220,6 +228,8 @@ SMTP validation is a final, third validation level. This type of validation trie | |
[Regex validation] -> [MX validation] -> [SMTP validation] | ||
``` | ||
|
||
If total count of MX servers is equal to one, ```Truemail::Smtp``` validator will use value from ```Truemail.configuration.connection_attempts``` as connection attempts. By default it's equal 2. | ||
|
||
By default, you don't need pass with-parameter to use it. Example of usage is specified below: | ||
|
||
With ```smtp_safe_check = false``` | ||
|
@@ -240,7 +250,7 @@ Truemail.validate('[email protected]') | |
success=true, | ||
email="[email protected]", | ||
domain="example.com", | ||
mail_servers=["mx1.example.com", "mx2.example.com"], | ||
mail_servers=["127.0.1.1", "127.0.1.2"], | ||
errors={}, | ||
smtp_debug=nil>, | ||
@validation_type=:smtp> | ||
|
@@ -252,7 +262,7 @@ Truemail.validate('[email protected]') | |
success=false, | ||
email="[email protected]", | ||
domain="example.com", | ||
mail_servers=["mx1.example.com", "mx2.example.com", "mx3.example.com"], | ||
mail_servers=["127.0.1.1", "127.0.1.2"], | ||
errors={:smtp=>"smtp error"}, | ||
smtp_debug= | ||
[#<Truemail::Validate::Smtp::Request:0x0000000002d49b10 | ||
|
@@ -261,20 +271,22 @@ Truemail.validate('[email protected]') | |
@connection_timeout=2, | ||
@email_pattern=/regex_pattern/, | ||
@response_timeout=2, | ||
@connection_attempts=2, | ||
@smtp_safe_check=false, | ||
@validation_type_by_domain={}, | ||
@verifier_domain="example.com", | ||
@verifier_email="[email protected]">, | ||
@email="[email protected]", | ||
@host="mx1.example.com", | ||
@host="127.0.1.1", | ||
@attempts=nil, | ||
@response= | ||
#<struct Truemail::Validate::Smtp::Response | ||
port_opened=true, | ||
connection=true, | ||
helo= | ||
#<Net::SMTP::Response:0x0000000002d5aca8 | ||
@status="250", | ||
@string="250 mx1.example.com Hello example.com\n">, | ||
@string="250 127.0.1.1 Hello example.com\n">, | ||
mailfrom= | ||
#<Net::SMTP::Response:0x0000000002d5a618 | ||
@status="250", | ||
|
@@ -303,7 +315,7 @@ Truemail.validate('[email protected]') | |
success=true, | ||
email="[email protected]", | ||
domain="example.com", | ||
mail_servers=["mx1.example.com"], | ||
mail_servers=["127.0.1.1", "127.0.1.2"], | ||
errors={}, | ||
smtp_debug= | ||
[#<Truemail::Validate::Smtp::Request:0x0000000002c95d40 | ||
|
@@ -312,20 +324,22 @@ Truemail.validate('[email protected]') | |
@connection_timeout=2, | ||
@email_pattern=/regex_pattern/, | ||
@response_timeout=2, | ||
@connection_attempts=2, | ||
@smtp_safe_check=true, | ||
@validation_type_by_domain={}, | ||
@verifier_domain="example.com", | ||
@verifier_email="[email protected]">, | ||
@email="[email protected]", | ||
@host="mx1.example.com", | ||
@host="127.0.1.1", | ||
@attempts=nil, | ||
@response= | ||
#<struct Truemail::Validate::Smtp::Response | ||
port_opened=true, | ||
connection=false, | ||
helo= | ||
#<Net::SMTP::Response:0x0000000002c934c8 | ||
@status="250", | ||
@string="250 mx1.example.com\n">, | ||
@string="250 127.0.1.1\n">, | ||
mailfrom=false, | ||
rcptto=nil, | ||
errors={:mailfrom=>"554 5.7.1 Client host blocked\n", :connection=>"server dropped connection after response"}>>,]>, | ||
|
@@ -338,7 +352,7 @@ Truemail.validate('[email protected]') | |
success=false, | ||
email="[email protected]", | ||
domain="example.com", | ||
mail_servers=["mx1.example.com", "mx2.example.com", "mx3.example.com"], | ||
mail_servers=["127.0.1.1", "127.0.1.2"], | ||
errors={:smtp=>"smtp error"}, | ||
smtp_debug= | ||
[#<Truemail::Validate::Smtp::Request:0x0000000002d49b10 | ||
|
@@ -347,20 +361,22 @@ Truemail.validate('[email protected]') | |
@connection_timeout=2, | ||
@email_pattern=/regex_pattern/, | ||
@response_timeout=2, | ||
@connection_attempts=2, | ||
@smtp_safe_check=true, | ||
@validation_type_by_domain={}, | ||
@verifier_domain="example.com", | ||
@verifier_email="[email protected]">, | ||
@email="[email protected]", | ||
@host="mx1.example.com", | ||
@host="127.0.1.1", | ||
@attempts=nil, | ||
@response= | ||
#<struct Truemail::Validate::Smtp::Response | ||
port_opened=true, | ||
connection=true, | ||
helo= | ||
#<Net::SMTP::Response:0x0000000002d5aca8 | ||
@status="250", | ||
@string="250 mx1.example.com Hello example.com\n">, | ||
@string="250 127.0.1.1 Hello example.com\n">, | ||
mailfrom=#<Net::SMTP::Response:0x0000000002d5a618 @status="250", @string="250 OK\n">, | ||
rcptto=false, | ||
errors={:rcptto=>"550 User not found\n"}>>]>, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
VERSION = '0.1.4' | ||
VERSION = '0.1.5' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Truemail | ||
RSpec.shared_examples 'request retry behavior' do | ||
before { error_stubs } | ||
|
||
context 'when attempts not exists' do | ||
specify do | ||
expect { response_instance_target_method }.to not_change(request_instance, :attempts) | ||
end | ||
end | ||
|
||
context 'when attempts exists' do | ||
let(:attempts) { { attempts: 5 } } | ||
|
||
specify do | ||
expect { response_instance_target_method }.to change(request_instance, :attempts).from(5).to(0) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.