ruby on railsアプリのメール送信でユーザーを確認する「確認できる」方法を実装しています。私のアプリの「development.log」ファイルには、メールが送信されたことが示されていますが、送信先に届きません。以下は、コードを含む私のファイルです:-
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :title, :body
def password_match?
self.errors[:password] << 'must be provided' if password.blank?
self.errors[:password] << 'and confirmation do not match' if password != password_confirmation
password == password_confirmation and !password.blank?
end
end
confirms_controller.rb
class ConfirmationsController < Devise::ConfirmationsController
def show
@user = User.find_by_confirmation_token(params[:confirmation_token])
end
ef confirm_user
@user = User.find_by_confirmation_token(params[:user][:confirmation_token])
if @user.update_attributes(params[:user]) and @user.password_match?
@user = User.confirm_by_token(@user.confirmation_token)
set_flash_message :notice, :confirmed
sign_in_and_redirect("user", @user)
else
render :show
end
end
サインアップページ
<h2>Sign up</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>
<div><%= f.submit "Sign up" %></div>
<% end %>
<%= render "devise/shared/links" %>
開発.rb
Gt::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "[username]",
:password => "[password]"
}
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
ログ出力
Sent mail to xy@gmail.com (2027ms)
Date: Wed, 27 Mar 2013 23:29:12 +0530
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: xy@gmail.com
Message-ID: <515333707f095_3501ae36c81486e@Vinay-PC.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome xy@gmail.com!</p>
<p>You can confirm your account email through the link below:</p>
問題: 開発ログからわかるように電子メールが送信されますが、指定された電子メール ID に到達しません。私はローカルホストにいます。どんな助けでも感謝します。
よろしく、 Vieneay Siingh