Class: ThecoreBackendCommons::SmtpTester

Inherits:
Object
  • Object
show all
Defined in:
lib/thecore_backend_commons/smtp_tester.rb

Overview

Sends a test email using the SMTP settings from ThecoreSettings. Usable from the Rails console or via the rake task.

From rails console:

ThecoreBackendCommons::SmtpTester.call("you@example.com")

From the shell:

rails thecore_backend_commons:smtp:test[you@example.com]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipient = nil) ⇒ SmtpTester

Returns a new instance of SmtpTester.



17
18
19
20
# File 'lib/thecore_backend_commons/smtp_tester.rb', line 17

def initialize(recipient = nil)
  @recipient = recipient.presence ||
               ThecoreSettings::Setting.find_by(ns: :mytask, key: :default_email)&.raw
end

Class Method Details

.call(recipient = nil) ⇒ Object



13
14
15
# File 'lib/thecore_backend_commons/smtp_tester.rb', line 13

def self.call(recipient = nil)
  new(recipient).call
end

Instance Method Details

#callObject



22
23
24
25
26
# File 'lib/thecore_backend_commons/smtp_tester.rb', line 22

def call
  validate!
  print_settings
  send_mail
end