2010-11-20 107 views
21

我正在使用Devise:confirmable和:recoverable模塊來確認用戶,並讓他在忘記密碼時讓他恢復密碼。一切正常,郵件得到生成,我可以在服務器日誌中看到它,但然後我面臨錯誤,郵件沒有傳遞到郵箱。 我的environment.rb文件中的SMTP設置是:用設計和Gmail smtp服務器發送郵件

require 'tlsmail' 
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) 
ActionMailer::Base.raise_delivery_errors = true 
ActionMailer::Base.perform_deliveries = true 
ActionMailer::Base.delivery_method = :smtp 

ActionMailer::Base.smtp_settings = { 
    :enable_starttls_auto => true, #this is the important shit! 
    :address => 'smtp.gmail.com', #'localhost', 
    :port => 587, 
    :tls => true, 
    :domain => 'mail.google.com', # mail.customdomain.com if you use google apps 
    :authentication => :login, 
    :user_name => '[email protected]', 
    :password => '_secret_password' 
} 

如果:地址是 'smtp.gmail.com',然後我得到以下錯誤:

SocketError (getaddrinfo: Name or service not known): 

如果我設置:地址爲「本地主機」,然後我得到以下錯誤:

Errno::ECONNREFUSED Connection refused - connect(2) 

我不知道這是什麼:地址意味着,所有這些東西是一個新手。 在運行UNAME -a,我得到

Linux jatin-ubuntu 2.6.32-24-generiC#38-Ubuntu SMP Mon Jul 5 09:22:14 UTC 2010 i686 GNU/Linux 

在我/etc/hosts中文件中的條目是:

127.0.0.1 localhost 
127.0.1.1 jatin-ubuntu 

*#74.125.93.109 smtp.gmail.com 
#The above entry added by me* 

# The following lines are desirable for IPv6 capable hosts 
::1  localhost ip6-localhost ip6-loopback 
fe00::0 ip6-localnet 
ff00::0 ip6-mcastprefix 
ff02::1 ip6-allnodes 
ff02::2 ip6-allrouters 
ff02::3 ip6-allhosts 

當我去掉了 'smtp.gmail.com' 地址在/ etc/hosts文件中,以下錯誤消失:

SocketError (getaddrinfo: Name or service not known): 

現在錯誤是:

Errno::ECONNREFUSED Connection refused - connect(2) 

我不知道怎麼回事,錯誤地搜索了一下,並嘗試了一切,但沒有什麼來拯救。 我確實已經安裝了'tlsmail' gem並且還有'郵件'寶石,我的應用程序處於開發模式。 幫助我解決這個錯誤,以便我可以愉快地繼續我的鐵路之旅,如果可能的話,引導我一點點:正確的方向地址問題,以便我瞭解這方面的基礎知識。 在此先感謝

回答

24

如果你仍然有這個問題,請嘗試使用這些設置:

require 'tlsmail'  
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE) 

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.perform_deliveries = true 
ActionMailer::Base.raise_delivery_errors = true 
ActionMailer::Base.smtp_settings = { 
    :enable_starttls_auto => true, 
    :address   => 'smtp.gmail.com', 
    :port    => 587, 
    :tls     => true, 
    :domain    => 'gmail.com', #you can also use google.com 
    :authentication  => :plain, 
    :user_name   => '[email protected]', 
    :password   => '_secret_password' 
} 

此外,我建議在你的配置/環境/ development.rb文件,而不是environment.rb中把這些設置,以便您可以指定不同的郵件服務器爲每個環境。

+0

謝謝你......真的有用。如果我有自己的域名和該域名的用戶名,您還可以記下設置嗎? – 2010-12-12 17:55:11

+0

只需將域名和用戶名更改爲[email protected] ...其他所有內容都應該相同。 – 2010-12-15 02:38:33

+0

使用此設置,它是否會將電子郵件從[email protected]發送到任何郵寄地址? – shibly 2011-10-09 01:43:05

0
+0

@Rio Tera:我是所有這些東西的新手,所以不明白你在指導我。您能否詳細說明一下 – 2010-11-20 12:32:11

+0

:域名可能應該是您域名的例子。com' – riotera 2010-11-20 13:06:10

+0

@Rio tera:直到現在我還沒有自己的域名,這是網站開發的新手。那我該怎麼做?擁有自己的域名是這個的先決條件?如果是的話,我會盡快購買一個 – 2010-11-21 01:38:16

相關問題