To use Truemail's global configuration features, you must first initialize it using Truemail.configure. This allows you to set parameters like the verifier email, timeouts, and validation types that will be used across your application.
Note that verifier_email is a required parameter and must be an existing email address used to perform the verification.
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.
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.
config.validation_type_for = { 'somedomain.com' => :regex, 'otherdomain.com' => :mx }
# Optional parameter. Validation of email which contains whitelisted emails always will return true.
config.whitelisted_emails = %w[user@somedomain1.com user@somedomain2.com]
# Optional parameter. Validation of email which contains blacklisted emails always will return false.
config.blacklisted_emails = %w[user@somedomain3.com user@somedomain4.com]
# Optional parameter. Validation of email which contains whitelisted domain always will return true.
config.whitelisted_domains = %w[somedomain1.com somedomain2.com]
# Optional parameter. Validation of email which contains blacklisted domain always will return false.
config.blacklisted_domains = %w[somedomain3.com somedomain4.com]
# Optional parameter. With this option Truemail will validate email which contains whitelisted domain only.
config.whitelist_validation = true
# Optional parameter. Filter out unwanted mx servers via predefined list of ip addresses.
config.blacklisted_mx_ip_addresses = %w[1.1.1.1 2.2.2.2]
# Optional parameter. Custom DNS gateway(s). Format: 'IP' or 'IP:PORT'.
config.dns = %w[10.0.0.1 10.0.0.2:54]
# Optional parameter. Use not RFC MX lookup flow.
config.not_rfc_mx_lookup_flow = true
# Optional parameter. SMTP port number. Default is 25.
config.smtp_port = 2525
# Optional parameter. Ends smtp validation session after first attempt on the first mx server in any fail cases.
config.smtp_fail_fast = true
# Optional parameter. Parse bodies of SMTP errors.
config.smtp_safe_check = true
# Optional parameter. Enable tracking events.
config.logger = {
tracking_event: :all,
stdout: true,
log_absolute_path: '/home/app/log/truemail.log'
}
end