0
我想在用戶註冊時發出簡單的電子郵件通知。如何創建電子郵件確認?
我的用戶註冊工作正常,我完全按照"Sending Email"教程,但無法使其正常工作。我究竟做錯了什麼?
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 => '[email protected]',
:password => 'thepassword'
}
型號/ user_mailer.rb
class UserMailer < ActionMailer::Base
def registration_confirmation(user)
recipients user.email
from "[email protected]"
subject "Thank you for Registering"
body "You are now registered on the Alpine Challenge!"
end
end
什麼部分是「不工作」? –
你確定'alp.domain..com'是對的嗎?它看起來不正確。 –
@Beau Grantham UserMailer.deliver_registration_confirmation(@user) - 它只是不發送電子郵件。一切看起來設置正確 –