views:

69

answers:

2

I have an app that has is up in a few environments i.e. (development, staging, beta, live)

What's the best way to pass in an app's domain name when sending mail, to allow for different domain names depending on the server?

My first thought is to add something in the respective environment.rb files for each one, so config/environments/beta.rb would contain

ActionMailer::Base.smtp_settings[:domain] = 'beta.domain.com'

And config/environments/staging.rb would contain

ActionMailer::Base.smtp_settings[:domain] = 'staging.domain.com'

This feels like I'm doing something so basic that Rails would already have this value lying around, but I haven't found it in any of the places I would normally expect, nor can i find it in the documentation.

What's the best approach to take here?

+1  A: 

In your environment files, you want to set:

ActionMailer::Base.default_url_options = { :host => "beta.domain.com" }

If you're using url_for instead of named routes, you also need to specify :only_path => false ... so you don't get relative urls. I generally try to use named routes, however.

Callmeed
Thanks this looks like it's just what I needed.Cheers Callmeed!
Chris Adams
+1  A: 

I usually just pass the value of request.host in to the ActionMailer method.

John Topley