传递 Rails 服务器域名进行邮件发送的最佳方式是什么?

发布于 2024-07-24 10:14:10 字数 487 浏览 1 评论 0原文

我有一个应用程序在几种环境中运行,即(开发、暂存、测试版、实时)

发送邮件时传递应用程序域名的最佳方式是什么,以允许根据服务器使用不同的域名?

我的第一个想法是在每个环境的各自的environment.rb文件中添加一些内容,因此config/environments/beta.rb将包含

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

并且config/environments/staging.rb会包含

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

这感觉就像我正在做一些非常基本的事情,Rails 已经有了这个值,但我没有在我通常期望的任何地方找到它,也无法在文档中找到它。

这里最好采取什么方法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾其所爱 2024-07-31 10:14:10

我通常只是将 request.host 的值传递给 ActionMailer 方法。

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

莫言歌 2024-07-31 10:14:10

在环境文件中,您需要设置:

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

如果您使用 url_for 而不是命名路由,则还需要指定 :only_path => false ...所以你不会得到相对网址。 不过,我通常尝试使用命名路由。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文