Search code examples
ruby-on-railsexception-notifier

To set exception recipients email in environment variable


As shown in code below, recipient's mails are hard-coded, how can I set them in environment variable

  Example::Application.config.middleware.use ExceptionNotification::Rack,
    :email => {
      email_prefix: "[Error] ",
      sender_address: %{"Exception Notifier" <[email protected]>},
      exception_recipients: %w{[email protected] [email protected]}
  }

I've tried exception_recipients: ENV['mail'] %w{ENV['mail']} "%w{#{ENV['mail']}}", but none works, it gives syntax error


Solution

  • Depends on the format you pass the mail variable in`. I'd probably go with semicolon separated list of email addresses.

    ENV["mail"] # => "[email protected];[email protected]"
    

    And then in the configuration:

    exception_recipients: String(ENV["mail"]).split(";")
    

    Notice the use of String to make sure it won't blow up on you if the key is not set (nil).