ローカルのすべてのメールは、Gmail アカウントで正常に動作します。ただし、本番環境では、マンドリルを使用してメールを配信しています。
私の問題は、ユーザーがパスワードをリセットしたいときです。これは本番環境での私のメール設定です:
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 でこのエラーを修正するにはどうすればよいですか?
ありがとう!