2011-03-16 60 views
2

我花了好幾天試圖讓這項工作=>我想從我的應用程序本地主機發送電子郵件,而無需使用Gmail或其他郵件服務器,所以我嘗試這樣做:問題與setup_email.rb的ActionMailer配置

/config/initializers/setup_email.rb

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = { 
    :address => "localhost", 
    :port => 25 
} 

但我得到 「拒絕連接 - 連接(2)」 錯誤消息類似以下內容:

Connection refused - connect(2) 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `initialize' 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `open' 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `do_start' 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/timeout.rb:67:in `timeout' 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/timeout.rb:101:in `timeout' 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `do_start' 
/home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:525:in `start' 
/home/user1/.rvm/gems/[email protected]/gems/mail-2.2.15/lib/mail/network/delivery_methods/smtp.rb:127:in `deliver!' 
/home/user1/.rvm/gems/[email protected]/gems/mail-2.2.15/lib/mail/message.rb:1967:in `do_delivery' 
/home/user1/.rvm/gems/[email protected]/gems/mail-2.2.15/lib/mail/message.rb:228:in `deliver' 
/home/user1/.rvm/gems/[email protected]/gems/actionmailer-3.0.3/lib/action_mailer/base.rb:401:in `deliver_mail' 
/home/user1/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/messages.rb:52:in `instrument' 
/home/user1/.rvm/gems/[email protected]/gems/activesupport-3.0.3/lib/active_support/messages/instrumenter.rb:21:in `instrument' 

...

如何配置本地主機爲的ActionMailer?

我搜索互聯網上,似乎我MUST提供用戶名並在配置密碼,並設置認證選項一定的價值,我可以配置的ActionMailer不認證用戶名密碼? (因爲我的應用程序沒有用於登錄的電子郵件帳戶) 如何配置使本地主機電子郵件發送功能正常工作?

+0

你運行你的電腦上的郵件服務器? – Augusto 2011-03-16 14:02:34

+0

不,我沒有。 – Mellon 2011-03-16 14:08:23

+0

啊哈,我剛剛發現我有'雷鳥' – Mellon 2011-03-16 14:09:27

回答

1

在本地主機上,你應該uusing sendmail的,一個良好的開端將是這個site

ActionMailer::Base.delivery_method = :sendmail 
ActionMailer::Base.sendmail_settings = { 
    :location  => '/usr/sbin/sendmail', 
    :arguments  => '-i -t' 
} 

我知道源是舊的,但似乎仍然有效

0

在本地主機上,你也可以使用mailtrap 。 blog post on mailtrap。還有更多documentation here。至於設置去,我把這個在我的初始化器

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.delivery_method = :test if Rails.env.test? 
ActionMailer::Base.smtp_settings = { 
:address => "localhost" 
:port => 2525, 
:domain => "localhost", 
} 

這種方法爲我工作。

4

添加到您的environment.rb:

ActionMailer::Base.delivery_method = :sendmail 
ActionMailer::Base.perform_deliveries = true 
ActionMailer::Base.raise_delivery_errors = true 
ActionMailer::Base.default_charset = "utf-8" 
+0

添加這個減去default_charset幫助我解決了這個問題。謝謝! – 2015-01-29 12:42:09