I’m working on Discourse Doctor.
As part of that, I’m adding a rake task to lib/tasks/emails.rake
to test connectivity to the mail server. The way that @joffreyjaffeux did it in a stand-alone ruby script was
def check_env_var(var)
if ENV[var].nil? || ENV[var].empty?
error("#{var} is blank, edit containers/app.yml variables")
end
end
check_env_var("DISCOURSE_SMTP_ADDRESS")
check_env_var("DISCOURSE_SMTP_PORT")
check_env_var("DISCOURSE_SMTP_USER_NAME")
check_env_var("DISCOURSE_SMTP_PASSWORD")
Net::SMTP.start(ENV["DISCOURSE_SMTP_ADDRESS"], ENV["DISCOURSE_SMTP_PORT"])
.auth_login(ENV["DISCOURSE_SMTP_USER_NAME"], ENV["DISCOURSE_SMTP_PASSWORD"])
That’s working, but is there a more Railsy/straightforward way to get those SMTP values from Rails rather than ENV?
I’m also not sure that the rake task needs to mention app.yml
, as I think that now discourse-setup
does a pretty good job of checking that up front, so I think that I can just remove the check_env_var
part.