我在本地的所有电子邮件都可以在我的 gmail 帐户中正常使用。但是在生产环境中,我使用mandrill来传递电子邮件。
我的问题是当用户想要重置密码时。这是我在生产中的电子邮件配置:
config.action_mailer.default_url_options = { :host => 'mydomain.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.asset_host = "mydomain.com"
ActionMailer::Base.default :from => 'hyperrjas@mydomain.com'
config.action_mailer.smtp_settings = {
:address => "smtp.mandrillapp.com",
:port => 25,
:user_name => Settings.email.username,
:password => Settings.email.password
}
这是我的邮件控制器:
require 'digest/sha2'
class UserMailer < Devise::Mailer
default "Message-ID"=>"#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@mydomain.com"
def confirmation_instructions(record, opts={})
set_locale(record)
headers["template_path"] = "user_mailer"
headers["template_name"] = "confirmation_instructions"
headers({'X-No-Spam' => 'True', 'In-Reply-To' => 'hyperrjas@mydomain.com'})
super
end
def reset_password_instructions(record, opts={})
set_locale(record)
headers["template_path"] = "user_mailer"
headers["template_name"] = "reset_password_instructions"
headers({'X-No-Spam' => 'True', 'In-Reply-To' => 'hyperrjas@mydomain.com'})
super
end
def unlock_instructions(record, opts={})
set_locale(record)
headers["template_path"] = "user_mailer"
headers["template_name"] = "unlock_instructions"
headers({'X-No-Spam' => 'True', 'In-Reply-To' => 'hyperrjas@mydomain.com'})
super
end
private
def set_locale(user)
I18n.locale = user.locale || I18n.default_locale
end
end
这是与生产中的问题的链接:
<%= link_to "Change password", edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
Mandrill 生成一个类似的链接:
http://mandrillapp.com/track/click.php?u=30029014&id=890aac6b235b4802883f75b484d5ac8f&url=http%3A%2F%2Fmydomain.com%2Fusers%2Fpassword%2Fedit&url_id=18754ce20fc88b338f0aa3993686e33be8ab84a1
但是在开发中工作正常:
http://localhost:3000/users/password/edit?reset_password_token=yzYyyZuZArq7ksLZdgh3
使用单击链接时,我可以看到错误:
You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided
如何使用 mandrill 修复此错误?
谢谢!