# How to set smpt server for our rails applicaion

**URL:** <https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801>\
**Category:** Rails\
**Created:** [July 28, 2009, 11:17am UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801 "2009-07-28T11:17:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 28, 2009, 11:17am UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/1 "2009-07-28T11:17:21Z")

</div>

hi i am using technoweenie-restful-authentication plug-in for  
authentication in my application. i want to send a activation link to  
the user’s mail-id.  
for that i need to set the smpt server for our rails application, for  
that i added the follwing code in config/environment.rb file

ActionMailer::Base.delivery\_method:smpt  
ActionMailer::Base.smpt\_settings = {  
:address =\> “localhost”,  
:port =\> 25,  
:authentication=\> :login,  
:user\_name =\> “my\_username”,  
:password =\> “my\_password”  
}

but when i try to run the server it gives the following errors

G:\my\MyMovies\>ruby script/server  
=\> Booting Mongrel  
=\> Rails 2.3.3 application starting on [http://0.0.0.0:3000](http://0.0.0.0:3000)  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active\_support/dependenci  
es.rb:443:in `load_missing_constant': uninitialized constant ActionMailer (NameE rror) from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_suppo rt/dependencies.rb:80:in `const\_missing’  
from  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active\_suppo  
rt/dependencies.rb:92:in `const_missing' from G:/my/MyMovies/config/environment.rb:43 from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.3/lib/initializer.rb:111:i n `run’  
from G:/my/MyMovies/config/environment.rb:9  
from  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in `ge m_original_require' from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `re  
quire’  
from  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active\_suppo  
rt/dependencies.rb:156:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_suppo rt/dependencies.rb:521:in `new\_constants\_in’  
from  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active\_suppo  
rt/dependencies.rb:156:in `require' from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.3.3/lib/commands/server.rb:8 4 from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `ge  
m\_original\_require’  
from  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in `re  
quire’  
from script/server:3

any anyone give me the procedure to add smpt server to my rails  
application  
is there any any code i need to add in my application to configure my  
application to the smpt server, if it is please tell me the procedure  
and which code i need to add.

regards,  
rajendra

---

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 28, 2009, 11:19am UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/2 "2009-07-28T11:19:55Z")

</div>

Did you include these…

ActionMailer::Base.raise\_delivery\_errors = true  
ActionMailer::Base.perform\_deliveries = true  
ActionMailer::Base.delivery\_method = :smtp

---

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 28, 2009, 11:31am UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/3 "2009-07-28T11:31:25Z")

</div>

Rails L. wrote:

> Did you include these…
> 
> ActionMailer::Base.raise\_delivery\_errors = true  
> ActionMailer::Base.perform\_deliveries = true  
> ActionMailer::Base.delivery\_method = :smtp

no, where can i include this code???

---

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 28, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/4 "2009-07-28T12:21:16Z")

</div>

On Jul 28, 5:17 am, Rajendra B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> hi i am using technoweenie-restful-authentication plug-in for  
> authentication in my application. i want to send a activation link to  
> the user’s mail-id.  
> for that i need to set the smpt server for our rails application, for  
> that i added the follwing code in config/environment.rb file

It looks like you’ve got this towards the top of environment.rb, i.e  
before the bit that runs the initializer: you don’t want this, the  
initializer is the thing that loads rails, so before it none of the  
rails framework (ActiveRecord, ActionMailer etc.) is loaded. You’ve  
also got a few typos in there.

Fred

---

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 28, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/5 "2009-07-28T17:41:30Z")

</div>

Don’t use environment.rb, use instead: “config/initializers/  
action\_mailer.rb”. Set it to read:

ActionMailer::Base.delivery\_method = :smtp

ActionMailer::Base.smtp\_settings = {  
:address =\> “localhost”,  
:port =\> 25,  
:authentication=\> :login,  
:user\_name =\> “my\_username”,  
:password =\> “my\_password”  
}

NOTE 1: delivery\_method = :smtp  
NOTE 2: smtp not smpt – two places

On Jul 28, 5:17 am, Rajendra B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 29, 2009, 3:35am UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/6 "2009-07-29T03:35:03Z")

</div>

On Jul 28, 7:50 pm, “Simon M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What’s the rational behind using initializers instead of environment files?  
> We are (and have been for some time) setting the smtp options in the  
> environment files with great success.

That rather than having environment.rb become a dumping ground you  
have a descriptively named set of files. Another incentive is that  
initializers run before your models are loaded (in production mode)  
whereas something at the bottom of environment.rb runs afterwards  
which can sometimes be problematic.

Fred

---

<div class="post-metadata">

**Author:** ![rajendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rajendra](https://www.ruby-forum.com/u/rajendra)\
**Post date:** [July 29, 2009, 1:52am UTC](https://www.ruby-forum.com/t/how-to-set-smpt-server-for-our-rails-applicaion/172801/7 "2009-07-29T01:52:04Z")

</div>

What’s the rational behind using initializers instead of environment  
files?  
We are (and have been for some time) setting the smtp options in the  
environment files with great success.

Cheers  
Simon
