我试图创造出发送当管理员点击活跃账户用户的ActionMailer为Appove帐户 - 电子邮件不发送
用户HAS_ONE电子邮件:户名及账号belongs_to的:用户
用户。 RB
devise :database_authenticatable, :registerable, :Trackable, :rememberable, :recoverable
attr_accessible :account, :email, :password, :password_confirmation, :account_attributes, :approved
has_one :account
end
在account.rb
class Account < ActiveRecord::Base
attr_accessible :address, :approved, :name
belongs_to :user
end
在accounts_controller.rb
def activate
@accounts = Account.find(params[:id])
@users = User.where(:id => @accounts.id)
if (@accounts.update_attributes(approved: true)) && (@users.update_all(approved: true))
AccountMailer.activate_account(@users).deliver
redirect_to accounts_path
else
redirect_to accounts_path
end
end
在account_mailer.rb
class AccountMailer < ActionMailer::Base
default :from => "[email protected]"
def activate_account(user)
@users = user
@account = account.find_by_user_id(user)
mail(:to => user.email, :subject => "Activation Account", :from => "[email protected]")
end
end
在account_mailer
/activate_account.text.erb
congratulation, your account is active now
setup_mailer.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "localhost:3000",
:user_name => "[email protected]",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
但邮件无法发送电子邮件用户,并没有错误.. 这些没有发生任何其他行动。
任何关于我在做什么的错误?
UPDATE 1
在accounts_controller.rbdef activate
@account = Account.find(params[:id])
@user = User.where(:id => @account.id)
if (@account.update_attributes(approved: true)) && (@user.update_all(approved: true))
AccountMailer.activate_account(@user,@account).deliver
redirect_to accounts_path
else
redirect_to accounts_path
end
end
在account_mailer.rb
class AccountMailer < ActionMailer::Base
default :from => "[email protected]"
def activate_account(user,account)
@account = account
@accounts = Account.find_by_user_id(user)
mail(:to => user.email, :subject => "Activation", :from => "[email protected]")
end
end
错误
undefined method `email' for #<ActiveRecord::Relation:0x3e7c720>
我以前遇到过这个问题,Gmail不理会电子邮件。你无能为力。我建议使用一个替代SMTP服务器,如sendgrid.com –
不,这些没有发生任何其他行为,smtp gmail正在为其他行动工作。 我认为控制器或邮件程序存在错误,但我不知道错误的位置。 – GeekToL
@users是accounts_controller.rb中的一个列表,而不仅仅是一行。使用“查找”而不是“where” –