Recommended way to get SMTP configuration


(Jay Pfaffman) #1

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.


(Jeff Atwood) #2

Nice to see this getting some :cupid:, the doctor :woman_health_worker: is in!


(Brahn) #3

Is this the right place?

Discourse::Application.config.action_mailer.smtp_settings


(Jay Pfaffman) #4

Looks like it! It’s obvious when you know. :slight_smile:

Many thanks!