【问题标题】:ActionMailer link host failing rails 3.1 and herokuActionMailer 链接主机失败 rails 3.1 和 heroku
【发布时间】:2012-04-16 09:49:17
【问题描述】:

我在从我的 heroku 应用程序发送的电子邮件中包含链接。我遵循了 ActionMailer railscast 并且在开发中一切都运行良好,但是当使用 heroku/sendgrid 时,链接是在没有主机的情况下发送的。例如,链接不是http://www.reelify.com/users/2,而是http://users/2

这是我在初始化程序中的 setup_mail.rb:

require 'development_mail_interceptor'

if Rails.env.production?
  ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name      => 'XXX',
  :password       => 'XXX',
  :domain         => 'heroku.com'
}
else
ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "reelify.com",
  :user_name            => "XXX",
  :password             => "XXX",
  :authentication       => "plain",
  :enable_starttls_auto => true
}
end

ActionMailer::Base.default_url_options[:host] = "reelify.com"


ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if    Rails.env.development?

我也尝试将此行添加到我的 production.rb 但现在在我测试时它被注释掉了:

config.action_mailer.default_url_options = {  :host => 'reelify.com' }

有人有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 heroku actionmailer


    【解决方案1】:

    我猜你是在电子邮件中输入路径而不是网址:

    users_path => /users
    users_url => http://localhost:3000/users
    

    在传出通信(电子邮件等)中,请始终确保您使用的是_urls

    【讨论】:

    • 啊,我明白了,这正是我正在做的。我有一个 link_to 助手,并使用“@user”作为 href。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 2020-07-15
    • 1970-01-01
    相关资源
    最近更新 更多