0

ユーザーがサインアップしたときに簡単な電子メール通知を作成しようとしています。

ユーザーのサインアップは正常に機能し、「電子メールの送信」チュートリアルに正確に従いましたが、機能しません。私は何を間違っていますか?

user_controller.rb

class Admin::UsersController < InheritedResources::Base
  before_filter :admin_only

  actions :index, :show, :new, :edit, :create, :update, :destroy
  respond_to :html

#  def new
#    @user = User.new(:invitation_token => params[:invitation_token])
#    @user.email = @user.invitation.recipient_email  
#  end  

  def create
    @user = User.new(params[:user])
    UserMailer.deliver_registration_confirmation(@user) < -- where I added the mailer
    @user.save(false)
    respond_to do |format|
      format.html{ redirect_to admin_users_path}
    end

  end

  private

  def collection
    paginate_options ||= {}
    paginate_options[:page] ||= (params[:page] || 1)
    paginate_options[:per_page] ||= (params[:per_page] || 20)
    @search = User.search(params[:search])
    @users ||= @search.all.paginate(paginate_options)
  end
end

環境/ production.rb

# Settings specified here will take precedence over those in config/environment.rb
config.action_mailer.default_url_options = { :host => 'alpine.totaline.com' }

config.action_mailer.raise_delivery_errors = true

# set delivery method to :smtp, :sendmail or :test
config.action_mailer.delivery_method = :smtp

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
  :address        => 'smtp.gmail.com',
  :port           => 25,
  :domain         => 'alpine.totaline.com',
  :authentication => :login,
  :user_name      => 'emailname@gmail.com',
  :password       => 'thepassword'
}

models/user_mailer.rb

class UserMailer < ActionMailer::Base
  def registration_confirmation(user)
    recipients  user.email
    from        "webmaster@alpinechallenge.com"
    subject     "Thank you for Registering"
    body        "You are now registered on the Alpine Challenge!"
  end  
end
4

1 に答える 1

1

Gmail の場合、ポート 587 を使用する必要があるようです。

# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
  :address        => 'smtp.gmail.com',
  :port           => '587',
  :domain         => 'alpine.totaline.com',
  :authentication => :login,
  :user_name      => 'emailname@gmail.com',
  :password       => 'thepassword'
}

このページには、Gmail で使用するメール クライアントの設定に関する注意事項が含まれています

于 2011-12-19T15:58:27.600 に答える