# Meilleure méthode pour obtenir la configuration SMTP

**URL:** <https://meta.discourse.org/t/recommended-way-to-get-smtp-configuration/90433>\
**Category:** Development\
**Created:** [Juin 21, 2018, 11:34 UTC](https://meta.discourse.org/t/recommended-way-to-get-smtp-configuration/90433 "2018-06-21T23:34:39Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [Juin 21, 2018, 11:34 UTC](https://meta.discourse.org/t/recommended-way-to-get-smtp-configuration/90433/1 "2018-06-21T23:34:39Z")

</div>

I’m working on [Discourse Doctor](https://github.com/jjaffeux/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 @j.jaffeux did it in a stand-alone ruby script was

```ruby
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.

---

_[View the full topic](https://meta.discourse.org/t/recommended-way-to-get-smtp-configuration/90433)._
