forked from External/greenlight
Test email configuration during setup (#1144)
* create proper test message and use correct env var for from address. designed to work with sandboxed AWS ses * use actionmailer in configuration test rake task * remove mailfactory gem * tidy up Gemfile and gem lock * fix rubocop issues * Update configuration.rake Co-authored-by: Ahmad Farhat <ahmad.af.farhat@gmail.com> Co-authored-by: Ahmad Farhat <ahmad.farhat@blindsidenetworks.com>
This commit is contained in:
parent
b89cbfad03
commit
f8a4f85193
|
@ -39,18 +39,8 @@ namespace :conf do
|
|||
end
|
||||
|
||||
def test_smtp
|
||||
smtp = Net::SMTP.new(ENV['SMTP_SERVER'], ENV['SMTP_PORT'])
|
||||
if ENV['SMTP_STARTTLS_AUTO']
|
||||
smtp.enable_starttls_auto if smtp.respond_to?(:enable_starttls_auto)
|
||||
end
|
||||
|
||||
user = ENV['SMTP_USERNAME'].presence || nil
|
||||
password = ENV['SMTP_PASSWORD'].presence || nil
|
||||
authtype = ENV['SMTP_AUTH'].present? && ENV['SMTP_AUTH'] != "none" ? ENV['SMTP_AUTH'] : nil
|
||||
|
||||
smtp.start(ENV['SMTP_DOMAIN'], user, password, authtype) do |s|
|
||||
s.sendmail('test', ENV['SMTP_USERNAME'], ENV.fetch('SMTP_TEST_RECIPIENT', 'notifications@example.com'))
|
||||
end
|
||||
TestMailer.test_email(ENV.fetch('SMTP_SENDER', 'notifications@example.com'),
|
||||
ENV.fetch('SMTP_TEST_RECIPIENT', 'notifications@example.com')).deliver
|
||||
rescue => e
|
||||
failed("Error connecting to SMTP - #{e}")
|
||||
end
|
||||
|
@ -83,3 +73,13 @@ end
|
|||
def passed
|
||||
print(": Passed\n")
|
||||
end
|
||||
|
||||
class TestMailer < ActionMailer::Base
|
||||
def test_email(sender, recipient)
|
||||
mail(to: recipient,
|
||||
from: sender,
|
||||
subject: "Greenlight Email Test",
|
||||
body: "This is what people with plain text mail readers will see.",
|
||||
content_type: "text/plain",)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue