【问题标题】:email not sent with a dot in the host name default_url_options[:host]未在主机名中使用点发送电子邮件 default_url_options[:host]
【发布时间】:2013-06-26 13:00:38
【问题描述】:

这是一个特别奇怪的问题... 我使用 Devise,当我要求重设密码时,我希望收到电子邮件。

所以我将这一行添加到我的 development.rb 文件中:

ActionMailer::Base.default_url_options[:host] = "localhost:3000"

这很好用……

但是如果我更改地址并在其中写一些带有点的内容,例如我的生产地址“xxx.herokuapp.com”,则不会发送邮件。我没有收到任何错误,在日志中我看到一条消息,告诉我邮件已发送,但我什么也没收到。

如果我提供的主机名中没有点 ('.'),我只会收到一封电子邮件。


编辑

如果我使用默认的 Devise:Mailer,一切正常。 一定是我的自定义 Mailer 有问题。

这里是: 邮件程序.rb

class Mailer < Devise::Mailer

  include Devise::Mailers::Helpers

  def headers_for(action, opts={})
    headers = {
        :subject       => t("devise.mailer.#{action}.subject"),
        :from          => mailer_sender(devise_mapping),
        :to            => resource.email,
        :bcc           => "myadresse",
        :template_path => template_paths
    }
  end

  def confirmation_instructions(record, opts={})
    devise_mail(record, :confirmation_instructions, opts)
  end

  def reset_password_instructions(record, opts={})
    devise_mail(record, :reset_password_instructions, opts)
  end

  def unlock_instructions(record, opts={})
    devise_mail(record, :unlock_instructions, opts)
  end

end

【问题讨论】:

  • 你是在修改development.rb还是production.rb
  • 请查看我在问题中的编辑。在开发和生产环境中,只要主机名中有一个点就会出现问题

标签: devise ruby-on-rails-3.2 actionmailer


【解决方案1】:

正如here 解释的那样,您可能必须像这样调用super

def headers_for(action, opts={})
    headers = super.merge({
        :subject       => t("devise.mailer.#{action}.subject"),
        :from          => mailer_sender(devise_mapping),
        :to            => resource.email,
        :bcc           => "myadresse",
        :template_path => template_paths
    })
end

【讨论】:

  • 感谢您的帮助!效果很好!
猜你喜欢
  • 2021-05-07
  • 2014-08-09
  • 1970-01-01
  • 2015-07-02
  • 2012-08-01
  • 2012-03-17
  • 1970-01-01
  • 2013-10-01
  • 2010-12-19
相关资源
最近更新 更多