uninitialized constant ActionMailer
A word to the wise of rails developers. Hopefully this makes it to Google search, because when I looked it up, there wasn’t an answer.
If you’re configuring ActionMailer and you try to run the console and get the following messages:
[host]$ script/console Loading development environment. ./script/../config/../config/environment.rb:41:NameError: uninitialized constant ActionMailer /home/highearth/.gems/gems/actionpack-1.12.1/lib/action_controller/integration.rb:15: NameError: uninitialized constant ActionController::Integration::Session::Test ./script/../config/../config/../app/controllers/application.rb:3: NameError: uninitialized constant ActionController::Base
Make sure your ActionMailer configuration in your config/environment.rb file is after your Rails::Initializer.run do |config| block.
My name is
June 23rd, 2006 at 3:15 am (#)
Hi Andrew,
Just wanted to say – excellent excellent tip. I’d reinstalled Ruby about 4 times trying to get ActionMailer to work; and all along it was just this config error. Rats!
Well, it’s solved now – so thanks a bunch.
June 23rd, 2006 at 8:09 am (#)
Glad it helped you!
June 29th, 2006 at 8:45 pm (#)
Thanks for the tip. You saved me a good amount of time I’m sure.
November 9th, 2006 at 9:56 am (#)
Nice one. Just what I needed.
November 20th, 2006 at 10:40 am (#)
thanks. it worked before but didn’t work afterwards… maybe because of an upgrade
now it works again, thanks
January 8th, 2007 at 12:23 am (#)
thanks andrew, it helped my time, i was wondering by seeing the error message.
January 21st, 2007 at 11:14 am (#)
I had it inside the block for rails 1.1.6 and it worked. When I upgrade to 1.2.1, it stopped working.
It wouldn’t be a big deal except that when it’s outside that block, the testing environment cannot set mail delivery to :test, which means that all my unit tests try to send e-mail through the SMTP server. They fail because the email addresses are bogus and not even legal (a@a.com).
Any ideas?
January 21st, 2007 at 11:18 am (#)
Well, luckily I’m using SMTP (the default). So, if I comment out the SMTP section, it will default to SMTP when necessary and use :test in the testing section.
I guess you could put SMTP in the production and development environments manually.
March 30th, 2007 at 3:21 am (#)
What does NameError Uninitialized Constant mean anyway?
April 15th, 2007 at 9:23 am (#)
In Ruby a Class is just an object, usually these objects are assigned to constants, variables that start with an uppercase letter. So ActionMailer is a constant that contains an instance of Class, namely the ActionMailer class. Since ActionMailer hasn’t been intialized you get a NameError : Uninitialized Constant.
Makes perfect sense
April 15th, 2007 at 9:24 am (#)
But that hasn’t solved my problem : I’d like to use ActionMailer _without_ rails, so I can’t use the rails initializer.
May 7th, 2007 at 5:15 am (#)
And to add to that, for the Republic of Stupid People, of whom I am a citizen…
Don’t remove the comment on:
# config.frameworks -= [ :action_web_service, :action_mailer ]
Right, with those wasted 2 hours out of my way, let’s code…
May 7th, 2007 at 9:41 am (#)
@Eric – Yeah, that will make it rather difficult for ActionMailer to work, when it’s been told to not be used.
May 8th, 2007 at 10:25 pm (#)
Thank you Sir! I’m sure you saved me some time there. Thank goodness I googled and found this.
June 20th, 2007 at 8:55 pm (#)
Hello! Good Site! Thanks you! wlbsncvqxppo
June 27th, 2007 at 3:35 pm (#)
Thanks for this site!
hifue.info
August 26th, 2007 at 1:14 pm (#)
Thanks a lot for the tip!!
By the way, first hit on google for the query!
Best regards,
escoz
September 19th, 2007 at 4:40 pm (#)
ok – in case anyone out there is a complete idiot like me – notice the instructions say to place the code following the config BLOCK. I was putting the code after the LINE, not the BLOCK. Whew – 24 hours later and I’m back in business!
December 6th, 2007 at 12:11 am (#)
Thanks for the tip. This worked a treat.
For some reason – having the directive in the block was working on an Apache fcgi server, but upon migrating to Mongrel I got this error.
December 6th, 2007 at 12:18 am (#)
[...] I found a solution here: http://highearthorbit.com/uninitialized-constant-actionmailer/ [...]
January 9th, 2008 at 7:09 am (#)
It has helped me too! Thanks a bunch.
January 10th, 2008 at 11:31 am (#)
Cheers!
January 17th, 2008 at 7:07 am (#)
Awsome! cheers mate
January 31st, 2008 at 2:09 pm (#)
Thanks!! You’re #1 on the google result for this error…
February 13th, 2008 at 12:02 pm (#)
Thank you for saving my sanity.
March 7th, 2008 at 6:53 am (#)
Woot! Thanks very much!
April 15th, 2008 at 7:43 am (#)
Oh!!! thanks a lot!
July 19th, 2008 at 9:31 pm (#)
Bless you, good sir.
August 29th, 2008 at 10:44 pm (#)
Thank you!
September 21st, 2008 at 1:17 pm (#)
Cheers Andrew, you just saved me a tonne of headaches…
February 23rd, 2009 at 11:05 pm (#)
Here it is 2009, I have just finished reading the 2008 edition of the “Rails Way”, and and Obie has devoted a whole 8 lines the the Actionmailer::Base.smtp_settings without once mentioning WHERE IN THE environment.rb file they are to be placed!
The lack of these kinds of details in the documentation have driven me to commit suicide by jumping out of the window 17 times in the last month. Thank God I live and work in a basement apartment.
Most the the time I think Rails is insanely brilliantly, but there are times when I think it it just plain insane.
Thank you Andrew.
March 7th, 2009 at 5:54 pm (#)
Huge help on that hint, would have taken me a while to realize. You are indeed the first google hit.
March 11th, 2009 at 5:01 am (#)
thx alot
You saved my day
August 26th, 2009 at 12:17 am (#)
yep – me too. thx for the tip.
September 17th, 2009 at 4:59 pm (#)
Wow! I can’t tell you how many tips and instructions, and how-to’s I have looked at never to find the place I should be putting the code… thanks a bunch!
January 2nd, 2010 at 6:35 pm (#)
Thanks, this was a little bit tricky, as all the example code was already inside the init block!
February 16th, 2010 at 2:36 pm (#)
Thanks, you saved my life