今天用了学习了点ruby的使用actionmailer发送电子邮件,看着教材写的,没想到还报错
首先要配置actionmailer的参数,指定邮件的发送方式,邮件服务器的地址以及账户信息等(就是这里报错了)
我之前的config/envirenment.rb是这样修改的
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.time_zone = 'UTC'
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings={
:address =>"smtp.***.com",
:port => **,
:domain =>"***.com",
:user_name =>"***",
:password =>"***",
:authentication => :login
}
end
当执行:ruby script\generate mailer WebMailer web时
错误如下:
D:/rubytest/rails_app/mailers/config/environment.rb:41: uninitialized constant A
ctionMailer (NameError)
from D:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:111:i
n `run'
from D:/rubytest/rails_app/mailers/config/environment.rb:9
from D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `ge
m_original_require'
from D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `re
quire'
from D:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/generate.rb
:1
from D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `ge
m_original_require'
from D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `re
quire'
from script/generate:3
解决方法:
要把你的配置参数放到最下面,Rails::Initializer.run do |config|这个块的外面,
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.time_zone = 'UTC'
end
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings={
:address =>"smtp.wlotx.com",
:port => 25,
:domain =>"wlotx.com",
:user_name =>"fengcx",
:password =>"abc123",
:authentication => :login
}
这样就可以了,呵呵!
参考:http://highearthorbit.com/uninitialized-constant-actionmailer/