### Execute Bundler to Install Gems Source: https://github.com/truemail-rb/truemail/blob/master/README.md This command-line instruction executes Bundler to install all gems specified in the application's Gemfile, including the Truemail gem. ```bash bundle ``` -------------------------------- ### Install Truemail Gem Directly Source: https://github.com/truemail-rb/truemail/blob/master/README.md This command-line instruction shows how to install the Truemail gem directly using the gem command, without relying on Bundler. ```bash gem install truemail ``` -------------------------------- ### Install Truemail Gem using Bundler Source: https://github.com/truemail-rb/truemail/blob/master/README.md This code snippet demonstrates how to add the Truemail gem to your application's Gemfile for installation via Bundler. It's a standard Ruby gem installation method. ```ruby gem 'truemail' ``` -------------------------------- ### Configure Truemail with Whitelist/Blacklist for Test/Staging Source: https://github.com/truemail-rb/truemail/blob/master/README.md Provides an example of configuring Truemail's whitelist and blacklist features within a Rails application's initializer (`config/initializers/truemail.rb`). This setup customizes validation behavior for non-production environments, utilizing predefined domain lists. ```ruby # config/initializers/truemail.rb Truemail.configure do |config| config.verifier_email = Rails.configuration.default_sender_email unless Rails.env.production? config.whitelisted_domains = Constants::Email::WHITE_DOMAINS config.blacklisted_domains = Constants::Email::BLACK_DOMAINS end end ``` -------------------------------- ### Global Configuration Setup for Truemail Source: https://context7.com/truemail-rb/truemail/llms.txt Sets up global configuration for Truemail at application startup. This includes verifier credentials, validation rules, timeouts, whitelists, blacklists, and logging settings. It allows customization of email patterns, SMTP error detection, and DNS servers. The configuration can be read, updated at runtime, or reset. ```ruby require 'truemail' Truemail.configure do |config| # Required: existing email on behalf of which verification will be performed config.verifier_email = 'verifier@example.com' # Optional: existing domain for verification (defaults to verifier_email domain) config.verifier_domain = 'mail.example.com' # Optional: customize email validation pattern config.email_pattern = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i # Optional: customize SMTP error detection pattern config.smtp_error_body_pattern = /(?=.*550)(?=.*(user|account|customer|mailbox)).*/i # Optional: connection timeout in seconds (default: 2) config.connection_timeout = 2 # Optional: SMTP response timeout in seconds (default: 2) config.response_timeout = 2 # Optional: total connection attempts (default: 2) config.connection_attempts = 3 # Optional: default validation type (:regex, :mx, :mx_blacklist, :smtp) config.default_validation_type = :smtp # Optional: per-domain validation type overrides config.validation_type_for = { 'trusted-domain.com' => :regex, 'suspicious-domain.com' => :smtp } # Optional: emails that always pass validation config.whitelisted_emails = %w[admin@company.com support@company.com] # Optional: emails that always fail validation config.blacklisted_emails = %w[spam@bad-domain.com] # Optional: domains that always pass validation config.whitelisted_domains = %w[trusted-partner.com verified-domain.com] # Optional: domains that always fail validation config.blacklisted_domains = %w[disposable-email.com temporary-mail.com] # Optional: only validate whitelisted domains, reject all others config.whitelist_validation = false # Optional: reject emails from MX servers with these IPs (DEA detection) config.blacklisted_mx_ip_addresses = %w[1.2.3.4 5.6.7.8] # Optional: custom DNS servers (format: ip or ip:port, default port: 53) config.dns = %w[8.8.8.8 1.1.1.1:53] # Optional: use simplified MX lookup (MX records only, not RFC compliant) config.not_rfc_mx_lookup_flow = false # Optional: custom SMTP port (default: 25) config.smtp_port = 25 # Optional: stop after first SMTP failure (default: false) config.smtp_fail_fast = false # Optional: parse SMTP error bodies for improved accuracy (default: false) config.smtp_safe_check = false # Optional: event logging configuration config.logger = { tracking_event: :all, # :all, :error, :recognized_error, :unrecognized_error stdout: true, log_absolute_path: '/var/log/truemail.log' } end # Read current configuration Truemail.configuration # Update configuration at runtime Truemail.configuration.connection_timeout = 5 Truemail.configuration.smtp_fail_fast = true # Reset configuration Truemail.reset_configuration! ``` -------------------------------- ### Mock DNS and SMTP for Testing with Truemail (Ruby) Source: https://context7.com/truemail-rb/truemail/llms.txt Details the setup for mocking DNS and SMTP services using the `dns_mock` and `smtp_mock` gems in a Ruby RSpec environment. This is crucial for end-to-end testing of email validation logic without relying on actual network services. It involves adding the gems to the test group in the Gemfile and including the respective helper modules in `spec_helper.rb`. ```ruby # Gemfile group :test do gem 'dns_mock', require: false gem 'smtp_mock', require: false end # spec/spec_helper.rb require 'dns_mock/test_framework/rspec' require 'smtp_mock/test_framework/rspec' RSpec.configure do |config| config.include DnsMock::TestFramework::RSpec::Helper config.include SmtpMock::TestFramework::RSpec::Helper end ``` -------------------------------- ### Configure and Use Truemail RFC MX Lookup (Ruby) Source: https://github.com/truemail-rb/truemail/blob/master/README.md This snippet shows how to configure Truemail with a verifier email and then use it to validate an email address using the default RFC MX lookup flow. It demonstrates the basic setup and the expected output structure of a successful validation. ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' end Truemail.validate('email@example.com', with: :mx) => #, configuration= #, @validation_type=:mx> ``` -------------------------------- ### Configure and Use SMTP Validation (Ruby) Source: https://github.com/truemail-rb/truemail/wiki/SMTP-validation Demonstrates how to configure and use Truemail's SMTP validation. It covers setting the verifier email and the `smtp_safe_check` option. The examples show the expected output for both successful and failed SMTP validations, including detailed error information. ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' end Truemail.validate('email@example.com') # Successful SMTP validation => #, configuration= #, @validation_type=:smtp> # SMTP validation failed => #"smtp error"}, smtp_debug= [#, @email="email@example.com", @host="127.0.1.1", @attempts=nil, @response= #, mailfrom= #, rcptto=false, errors={:rcptto=>"550 User not found\n"}>>]>, configuration= #, @validation_type=:smtp> ``` ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.smtp_safe_check = true end Truemail.validate('email@example.com') ``` -------------------------------- ### Truemail SMTP Validation Failure Example Source: https://github.com/truemail-rb/truemail/blob/master/README.md Illustrates a scenario where SMTP validation fails due to an invalid recipient. It shows the detailed error structure, including SMTP debug information and configuration settings. ```ruby # SMTP validation failed => #"smtp error"}, smtp_debug= [# @email="email@example.com", @host="127.0.1.1", @attempts=nil, @response= # rcptto=false, errors={:rcptto=>"550 User not found\n"}>>]>, configuration= #, @validation_type=:smtp> ``` -------------------------------- ### Configure Truemail with Whitelist and Blacklist Domains (Ruby) Source: https://github.com/truemail-rb/truemail/wiki/Whitelist-Blacklist-check Configures the Truemail gem with specific whitelisted and blacklisted domains, and sets validation types for certain domains. This setup determines how emails from these domains are handled during validation. ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.whitelisted_domains = ['white-domain.com', 'somedomain.com'] config.blacklisted_domains = ['black-domain.com', 'somedomain.com'] config.validation_type_for = { 'somedomain.com' => :mx } end ``` -------------------------------- ### Update Truemail Global Configuration Source: https://github.com/truemail-rb/truemail/blob/master/README.md Modifies specific parameters of the global Truemail configuration. This example demonstrates updating connection timeout, response timeout, and connection attempts. Changes are reflected immediately in the configuration object. ```ruby Truemail.configuration.connection_timeout = 3 => 3 Truemail.configuration.response_timeout = 4 => 4 Truemail.configuration.connection_attempts = 1 => 1 Truemail.configuration => # :regex, "otherdomain.com" => :mx}, @whitelisted_emails=["user@somedomain1.com", "user@somedomain2.com"], @blacklisted_emails=["user@somedomain3.com", "user@somedomain4.com"], @whitelisted_domains=["somedomain1.com", "somedomain2.com"], @blacklisted_domains=["somedomain3.com", "somedomain4.com"], @whitelist_validation=true, @blacklisted_mx_ip_addresses=["1.1.1.1", "2.2.2.2"], @dns=["10.0.0.1", "10.0.0.2:54"], @verifier_domain="somedomain.com", @verifier_email="verifier@example.com", @not_rfc_mx_lookup_flow=true, @smtp_port=2525, @smtp_fail_fast=true, @smtp_safe_check=true, @logger=#> ``` -------------------------------- ### Configure Whitelist/Blacklist in Truemail Ruby Source: https://github.com/truemail-rb/truemail/blob/master/README.md Configures Truemail with whitelisted and blacklisted emails and domains. This setup is crucial for defining exceptions and restrictions in email validation. It requires the 'truemail' gem. ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.whitelisted_emails = %w[user@somedomain1.com user@somedomain2.com] config.blacklisted_emails = %w[user@somedomain3.com user@somedomain4.com] config.whitelisted_domains = %w[white-domain.com somedomain.com] config.blacklisted_domains = %w[black-domain.com somedomain.com] config.validation_type_for = { 'somedomain.com' => :mx } end ``` -------------------------------- ### Truemail Validator #as_json Method Source: https://github.com/truemail-rb/truemail/blob/master/README.md Demonstrates the use of the `#as_json` method on a Truemail validator object to get a JSON representation of the validation results. This is useful for serializing validation outcomes. ```Ruby result = Truemail.validate('test@example.com') json_output = result.as_json puts json_output ``` -------------------------------- ### Blacklist Email Validation Case (Ruby) Source: https://github.com/truemail-rb/truemail/blob/master/README.md This example shows how Truemail handles an email address present in its blacklist. The validation result will be 'success: false', and the validation type will be set to ':blacklist'. The output displays the validation result object. ```ruby Truemail.validate('email@black-domain.com') #, configuration= #, @validation_type=:blacklist> ``` -------------------------------- ### Stub Truemail Validation in RSpec Tests (Ruby) Source: https://context7.com/truemail-rb/truemail/llms.txt Provides examples of how to stub Truemail validation methods within an RSpec test environment using Ruby. This allows developers to isolate their application logic from actual email validation services during testing. Stubbing can be applied to the `valid?` helper, the `validate` method, or the full validation chain. ```ruby # spec/spec_helper.rb require 'truemail' RSpec.configure do |config| # Stub valid? helper config.before { allow(Truemail).to receive(:valid?).and_return(true) } # Or stub validate method config.before { allow(Truemail).to receive(:validate).and_return(true) } # Or stub full validation chain config.before do allow(Truemail).to receive_message_chain(:validate, :result, :valid?).and_return(true) end end # Whitelist/blacklist approach for staging environment # config/initializers/truemail.rb Truemail.configure do |config| config.verifier_email = 'verifier@example.com' unless Rails.env.production? config.whitelisted_domains = %w[test-domain.com staging-domain.com] config.blacklisted_domains = %w[blocked-test-domain.com] end end ``` -------------------------------- ### Serialize Truemail Auditor Instance to JSON in Ruby Source: https://github.com/truemail-rb/truemail/blob/master/README.md Serializes a Truemail::Auditor instance into a JSON string. This provides a structured representation of the host audit results, including warnings and configuration details. The `Truemail.host_audit` method is used to get the auditor instance. ```ruby Truemail::Log::Serializer::AuditorJson.call(Truemail.host_audit) ``` -------------------------------- ### Configure Truemail Not RFC MX Lookup (Ruby) Source: https://github.com/truemail-rb/truemail/blob/master/README.md This snippet demonstrates how to enable the 'not RFC MX lookup flow' in Truemail by setting `not_rfc_mx_lookup_flow` to true during configuration. This changes the MX record resolution to use a single resolver, and the example shows this configuration along with a subsequent validation call. ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.not_rfc_mx_lookup_flow = true end Truemail.validate('email@example.com', with: :mx) => #, configuration= #, @validation_type=:mx> ``` -------------------------------- ### Mock DNS and SMTP Services for Truemail Integration Tests Source: https://github.com/truemail-rb/truemail/blob/master/README.md Demonstrates an end-to-end testing approach for Truemail by mocking DNS and SMTP services using the `dns_mock` and `smtp_mock` gems. This involves setting up mock servers, configuring Truemail to use their ports, and defining test scenarios for valid and invalid email addresses. ```ruby # Gemfile group :test do gem 'dns_mock', require: false gem 'smtp_mock', require: false end # spec/spec_helper.rb require 'dns_mock/test_framework/rspec' require 'smtp_mock/test_framework/rspec' RSpec.configure do |config| config.include DnsMock::TestFramework::RSpec::Helper config.include SmtpMock::TestFramework::RSpec::Helper end # spec/integration_spec.rb RSpec.describe 'integration tests' do let(:target_email) { random_email } let(:dns_mock_records) { dns_mock_records_by_email(target_email, dimension: 2) } before do dns_mock_server.assign_mocks(dns_mock_records) smtp_mock_server(**smtp_mock_server_options) Truemail.configuration.tap do |config| config.dns = %W[127.0.0.1:#{dns_mock_server.port}] config.smtp_port = smtp_mock_server.port end end context 'when checks real email' do let(:smtp_mock_server_options) { {} } it { expect(Truemail.validate(target_email).result).to be_valid } end context 'when checks fake email' do let(:smtp_mock_server_options) { { not_registered_emails: [target_email] } } it { expect(Truemail.validate(target_email).result).not_to be_valid } end end ``` -------------------------------- ### Configure Truemail Gem Settings Source: https://github.com/truemail-rb/truemail/wiki/Setting-global-configuration This snippet demonstrates how to configure the Truemail gem using a block. It covers essential settings like verifier email, domain patterns, timeouts, validation rules, whitelisting, blacklisting, and logging. Dependencies include the 'truemail' gem itself. ```ruby require 'truemail' Truemail.configure do |config| # Required parameter. Must be an existing email on behalf of which verification will be performed config.verifier_email = 'verifier@example.com' # Optional parameter. Must be an existing domain on behalf of which verification will be performed. # By default verifier domain based on verifier email config.verifier_domain = 'somedomain.com' # Optional parameter. You can override default regex pattern config.email_pattern = /regex_pattern/ # Optional parameter. You can override default regex pattern config.smtp_error_body_pattern = /regex_pattern/ # Optional parameter. Connection timeout is equal to 2 ms by default. config.connection_timeout = 1 # Optional parameter. A SMTP server response timeout is equal to 2 ms by default. config.response_timeout = 1 # 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 default validation type for # Truemail.validate('email@email.com') call without with-parameter # Available validation types: :regex, :mx, :smtp config.default_validation_type = :mx # Optional parameter. You can predefine which type of validation will be used for domains. # Also you can skip validation by domain. Available validation types: :regex, :mx, :smtp # This configuration will be used over current or default validation type parameter # All of validations for 'somedomain.com' will be processed with regex validation only. # And all of validations for 'otherdomain.com' will be processed with mx validation only. # It is equal to empty hash by default. config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx } # Optional parameter. Validation of email which contains whitelisted domain always will # return true. Other validations will not processed even if it was defined in validation_type_for # It is equal to empty array by default. config.whitelisted_domains = ['somedomain1.com', 'somedomain2.com'] # Optional parameter. With this option Truemail will validate email which contains whitelisted # domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators. # Validation of email which not contains whitelisted domain always will return false. # It is equal false by default. config.whitelist_validation = true # Optional parameter. Validation of email which contains blacklisted domain always will # return false. Other validations will not processed even if it was defined in validation_type_for # It is equal to empty array by default. config.blacklisted_domains = ['somedomain1.com', 'somedomain2.com'] # Optional parameter. This option will be parse bodies of SMTP errors. It will be helpful # if SMTP server does not return an exact answer that the email does not exist # By default this option is disabled, available for SMTP validation only. config.smtp_safe_check = true # Optional parameter. This option will enable tracking events. You can print tracking events to # stdout, write to file or both of these. Tracking event by default is :error # Available tracking event: :all, :unrecognized_error, :recognized_error, :error config.logger = { tracking_event: :all, stdout: true, log_absolute_path: '/home/app/log/truemail.log' } end ``` -------------------------------- ### Read Truemail Global Configuration Source: https://github.com/truemail-rb/truemail/wiki/Setting-global-configuration This snippet shows how to access the current configuration of the Truemail gem after it has been set up. It displays the active settings for verifier email, domain, timeouts, and other parameters. ```ruby Truemail.configuration => #> ``` -------------------------------- ### Configure Truemail with Custom Settings (Ruby) Source: https://github.com/truemail-rb/truemail/wiki/Using-custom-independent-configuration Demonstrates how to create and use a custom configuration object for Truemail. This allows specific settings like the verifier email to be applied to individual validation or audit calls. Ensure you have either a global or custom configuration to use the Truemail gem. ```ruby custom_configuration = Truemail::Configuration.new do |config| config.verifier_email = 'verifier@example.com' end Truemail.validate('email@example.com', custom_configuration: custom_configuration) Truemail.valid?('email@example.com', custom_configuration: custom_configuration) Truemail.host_audit('email@example.com', custom_configuration: custom_configuration) ``` -------------------------------- ### Ruby: Truemail Email Validation Integration Test Source: https://context7.com/truemail-rb/truemail/llms.txt This Ruby code snippet demonstrates integration testing for the Truemail gem. It sets up mock DNS and SMTP servers to simulate email validation scenarios, including checking for valid emails, non-existent emails, and validating with MX records only. It configures Truemail with mock server ports and then asserts the validation results. ```ruby RSpec.describe 'Email validation integration' do let(:target_email) { 'test@example.com' } let(:dns_records) do { 'example.com' => { mx: [{ name: 'mail.example.com', priority: 10 }], a: ['127.0.0.1'] } } end before do dns_mock_server.assign_mocks(dns_records) smtp_mock_server(not_registered_emails: []) Truemail.configuration.tap do |config| config.dns = ["127.0.0.1:#{dns_mock_server.port}"] config.smtp_port = smtp_mock_server.port end end context 'when email exists' do it 'validates successfully' do result = Truemail.validate(target_email) expect(result.result).to be_valid expect(result.result.mail_servers).to eq(['127.0.0.1']) end end context 'when email does not exist' do before do smtp_mock_server(not_registered_emails: [target_email]) end it 'fails validation' do result = Truemail.validate(target_email) expect(result.result).not_to be_valid expect(result.result.errors).to have_key(:smtp) end end context 'when using MX validation only' do it 'checks DNS records without SMTP' do result = Truemail.validate(target_email, with: :mx) expect(result.validation_type).to eq(:mx) expect(result.result).to be_valid end end end ``` -------------------------------- ### Update Truemail Global Configuration (Ruby) Source: https://github.com/truemail-rb/truemail/wiki/Setting-global-configuration This snippet demonstrates how to update global configuration settings for Truemail, such as connection timeout, response timeout, and connection attempts. It also shows how to view the current configuration object. No external dependencies are required beyond the Truemail gem itself. ```ruby Truemail.configuration.connection_timeout = 3 Truemail.configuration.response_timeout = 4 Truemail.configuration.connection_attempts = 1 Truemail.configuration ``` -------------------------------- ### Configure and Validate Email with Default Regex Pattern Source: https://github.com/truemail-rb/truemail/wiki/Regex-validation This Ruby code demonstrates how to configure Truemail with a verifier email and then validate an email address using the default regex pattern. It shows the expected output structure of the Truemail validator result. ```ruby require 'truemail' Truemail.configure do |config| config.verifier_email = 'verifier@example.com' end Truemail.validate('email@example.com', with: :regex) => #, configuration= #, @validation_type=:regex> ``` -------------------------------- ### Serialize Truemail Validator Instance to JSON Source: https://github.com/truemail-rb/truemail/blob/master/README.md Illustrates the use of the `#as_json` helper to convert a `Truemail::Validator` instance into a JSON representation. This provides a structured output of the email validation process, including errors and configuration details. It depends on `Truemail::Log::Serializer::ValidatorJson`. ```ruby Truemail.validate('nonexistent_email@bestweb.com.ua').as_json ``` -------------------------------- ### Configure Truemail Event Logging in Ruby Source: https://context7.com/truemail-rb/truemail/llms.txt Explains how to configure Truemail's event logging. This includes options for logging to standard output, a specified file path, or a custom logger instance. Different tracking event levels like :all, :error, :recognized_error, and :unrecognized_error can be specified. ```ruby require 'truemail' # Standard logger to file and stdout Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.logger = { tracking_event: :all, # Track all events stdout: true, # Print to console log_absolute_path: '/var/log/truemail.log' # Write to file } end # Logger with error tracking only Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.logger = { tracking_event: :error, # Track errors only stdout: false, log_absolute_path: '/var/log/truemail_errors.log' } end # Custom logger instance require 'logger' custom_logger = Logger.new($stdout) custom_logger.level = Logger::WARN custom_logger.formatter = proc do |severity, datetime, progname, msg| "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S')}]: #{msg}\n" end Truemail.configure do |config| config.verifier_email = 'verifier@example.com' config.logger = { custom_logger: custom_logger } end ``` -------------------------------- ### Configure Global Settings for Truemail Source: https://github.com/truemail-rb/truemail/blob/master/README.md Demonstrates how to set, read, update, and reset global configuration for the Truemail validator. This affects all subsequent validations unless overridden by custom configurations. ```Ruby Truemail.configure do |config| config.verify_mx = false config.verifier_email = 'default@example.com' end puts Truemail.config.to_h Truemail.setup(logger: Logger.new(STDOUT)) Truemail.reset ``` -------------------------------- ### Perform Truemail Host Audit Source: https://github.com/truemail-rb/truemail/blob/master/README.md This Ruby code snippet demonstrates how to initiate a host audit using the Truemail gem. The audit checks the current host's internet connectivity, IP address, DNS records, and PTR records. It returns a result object indicating the success of the audit and any potential warnings. ```ruby Truemail.host_audit ``` -------------------------------- ### Truemail Validator .valid? Method Source: https://github.com/truemail-rb/truemail/blob/master/README.md Illustrates the usage of the `.valid?` method provided by Truemail for a concise boolean check of email validity. This is a common shortcut for simple validation checks. ```Ruby is_valid = Truemail.valid?('test@example.com') puts is_valid # => true or false ``` -------------------------------- ### Quick Email Validation with Truemail.valid? in Ruby Source: https://github.com/truemail-rb/truemail/blob/master/README.md Provides a convenient shortcut method `.valid?` for a quick boolean check of an email address's validity. This method is equivalent to calling `Truemail.validate(email).result.valid?`. ```ruby # It is shortcut for Truemail.validate('email@example.com').result.valid? Truemail.valid?('email@example.com') ``` -------------------------------- ### Custom Independent Configuration for Truemail Source: https://context7.com/truemail-rb/truemail/llms.txt Creates standalone configuration instances for specific validation scenarios without affecting the global settings. This allows for per-validation customization of verifier email, default validation type, connection timeouts, and SMTP fail-fast behavior. These custom configurations can then be passed to validation methods. ```ruby require 'truemail' # Create custom configuration custom_config = Truemail::Configuration.new do |config| config.verifier_email = 'custom-verifier@example.com' config.default_validation_type = :mx config.connection_timeout = 3 config.smtp_fail_fast = true end # Use custom configuration for validation Truemail.validate('test@example.com', custom_configuration: custom_config) # Use custom configuration for quick validation check Truemail.valid?('test@example.com', custom_configuration: custom_config) # Use custom configuration for host audit Truemail.host_audit(custom_configuration: custom_config) ``` -------------------------------- ### Configure Truemail Global Settings in Ruby Source: https://github.com/truemail-rb/truemail/blob/master/README.md This Ruby code snippet demonstrates how to configure global settings for the Truemail gem. It includes setting the verifier email, domain, custom regex patterns, timeouts, and various whitelisting/blacklisting options for emails and domains. ```ruby require 'truemail' Truemail.configure do |config| # Required parameter. Must be an existing email on behalf of which verification will be performed config.verifier_email = 'verifier@example.com' # Optional parameter. Must be an existing domain on behalf of which verification will be performed. # By default verifier domain based on verifier email config.verifier_domain = 'somedomain.com' # Optional parameter. You can override default regex pattern config.email_pattern = /regex_pattern/ # Optional parameter. You can override default regex pattern config.smtp_error_body_pattern = /regex_pattern/ # Optional parameter. Connection timeout in seconds. # It is equal to 2 by default. config.connection_timeout = 1 # Optional parameter. A SMTP server response timeout in seconds. # It is equal to 2 by default. config.response_timeout = 1 # 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 default validation type for # Truemail.validate('email@email.com') call without with-parameter # Available validation types: :regex, :mx, :mx_blacklist, :smtp config.default_validation_type = :mx # Optional parameter. You can predefine which type of validation will be used for domains. # Also you can skip validation by domain. # Available validation types: :regex, :mx, :mx_blacklist, :smtp # This configuration will be used over current or default validation type parameter # All of validations for 'somedomain.com' will be processed with regex validation only. # And all of validations for 'otherdomain.com' will be processed with mx validation only. # It is equal to empty hash by default. config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx } # Optional parameter. Validation of email which contains whitelisted emails always will # return true. Other validations will not processed even if it was defined in validation_type_for # It is equal to empty array by default. config.whitelisted_emails = %w[user@somedomain1.com user@somedomain2.com] # Optional parameter. Validation of email which contains blacklisted emails always will # return false. Other validations will not processed even if it was defined in validation_type_for # It is equal to empty array by default. config.blacklisted_emails = %w[user@somedomain3.com user@somedomain4.com] # Optional parameter. Validation of email which contains whitelisted domain always will # return true. Other validations will not processed even if it was defined in validation_type_for # It is equal to empty array by default. config.whitelisted_domains = %w[somedomain1.com somedomain2.com] # Optional parameter. Validation of email which contains blacklisted domain always will # return false. Other validations will not processed even if it was defined in validation_type_for # It is equal to empty array by default. config.blacklisted_domains = %w[somedomain3.com somedomain4.com] # Optional parameter. With this option Truemail will validate email which contains whitelisted # domain only, i.e. if domain whitelisted, validation will passed to Regex, MX or SMTP validators. # Validation of email which not contains whitelisted domain always will return false. # It is equal false by default. config.whitelist_validation = true # Optional parameter. With this option Truemail will filter out unwanted mx servers via # predefined list of ip addresses. It can be used as a part of DEA (disposable email # address) validations. It is equal to empty array by default. config.blacklisted_mx_ip_addresses = %w[1.1.1.1 2.2.2.2] # Optional parameter. This option will provide to use custom DNS gateway when Truemail # interacts with DNS. Valid port numbers are in the range 1-65535. If you won't specify # nameserver's ports Truemail will use default DNS TCP/UDP port 53. By default Truemail # uses DNS gateway from system settings and this option is equal to empty array. config.dns = %w[10.0.0.1 10.0.0.2:54] # Optional parameter. This option will provide to use not RFC MX lookup flow. # It means that MX and Null MX records will be cheked on the DNS validation layer only. # By default this option is disabled. config.not_rfc_mx_lookup_flow = true # Optional parameter. SMTP port number. It is equal to 25 by default. config.smtp_port = 2525 # Optional parameter. This option will provide to use smtp fail fast behavior. When # smtp_fail_fast = true it means that Truemail ends smtp validation session after first end ```