使用此通知程序
class Notifier < ActionMailer::Base
default_url_options[:host] = "url"
def deliver_password_reset_instructions(user)
@user = user
@subject = 'Password reset instructions.'
@sent_on = Time.now
#default host is defined in development.rb configuration file
@edit_password_reset_url = url_for :controller => 'password_reset', :action => 'edit'
@edit_password_reset_url += "?id=#{user.perishable_token}"
mail to: user.email
end
end
并在config / environments / development.rb上使用此配置
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = {
:host => 'localhost',
:port => '3000'
}
# Options: :smtp, :test
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'mymail',
:password => 'mypassword',
:authentication => :plain,
:enable_starttls_auto => true }
它没有发送什么,有什么问题?
答案 0 :(得分:0)
在此帖Actionmailer not working when I change gmail password
中设置操作邮件将通知程序编辑为: -
class Notifier < ActionMailer::Base
default from: "test@example.com"
def deliver_password_reset_instructions(user)
@user = user
@sent_on = Time.now
#default host is defined in development.rb configuration file
@edit_password_reset_url = url_for :controller => 'password_reset', :action => 'edit'
@edit_password_reset_url += "?id=#{user.perishable_token}"
mail to: user.email, :subject => "Password reset instructions."
end
end
在password_reset_controller中: -
def create
#send email as
Notifier.deliver_password_reset_instructions(user)
end
在 app / views / notifier / 中创建一个名为 deliver_password_reset_instructions.html.erb 的页面,并放置通过邮件发送的内容。