2010-11-20 382 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

相关问题