我像这样配置了environment.rb文件:
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
rapp::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: :login, # will send password Base64 encoded
user_name: "myadress",
password: "mypass",
enable_starttls_auto: true
}
end
但是当我尝试生成这样的邮件程序时:
rails generate mailer MailNotifier template1 template2 template3
我收到了这个错误:
/home/usr/.../rapp/config/environment.rb:7:in `<top (required)>': undefined local variable or method `rapp' for main:Object (NameError)
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/application.rb:264:in `require'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/application.rb:264:in `require_environment!'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:147:in `require_application_and_environment!'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:133:in `generate_or_destroy'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:51:in `generate'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/usr/.rvm/gems/ruby-2.1.0/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
有人可以帮忙解决这个问题吗?
答案 0 :(得分:0)
将您的action_mailer设置为: -
http://stackoverflow.com/questions/23300150/actionmailer-not-working-when-i-change-gmail-password/23300459#23300459
从 environment.rb 文件
中删除此内容rapp::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
authentication: :login, # will send password Base64 encoded
user_name: "myadress",
password: "mypass",
enable_starttls_auto: true
}
end
然后尝试: -
rails generate mailer MailNotifier template1 template2 template3