setup_email.rb 中的 ActionMailer 配置有问题
我花了几天时间试图完成这项工作=>我想从我的应用程序 localhost 发送电子邮件,不使用 gmail 或其他邮件服务器,所以我尝试了以下操作:
在 /config/initializers/setup_email.rb 中
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 25
}
但我收到“连接被拒绝 - connect(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/ruby-1.8.7-p330@myapp/gems/mail-2.2.15/lib/mail/network/delivery_methods/smtp.rb:127:in `deliver!'
/home/user1/.rvm/gems/ruby-1.8.7-p330@myapp/gems/mail-2.2.15/lib/mail/message.rb:1967:in `do_delivery'
/home/user1/.rvm/gems/ruby-1.8.7-p330@myapp/gems/mail-2.2.15/lib/mail/message.rb:228:in `deliver'
/home/user1/.rvm/gems/ruby-1.8.7-p330@global/gems/actionmailer-3.0.3/lib/action_mailer/base.rb:401:in `deliver_mail'
/home/user1/.rvm/gems/ruby-1.8.7-p330@global/gems/activesupport-3.0.3/lib/active_support/messages.rb:52:in `instrument'
/home/user1/.rvm/gems/ruby-1.8.7-p330@global/gems/activesupport-3.0.3/lib/active_support/messages/instrumenter.rb:21:in `instrument'
...
如何为 ActionMailer 配置 localhost?
我在互联网上搜索,似乎我必须在配置中提供用户名和密码,并设置身份验证选项到某个值,我可以在没有身份验证、用户名和密码的情况下配置 ActionMailer 吗? (因为我的应用程序没有用于登录的电子邮件帐户) 如何配置以使本地主机电子邮件发送功能正常工作?
I spent several days trying to get this work => I would like to send email from my application localhost, without using gmail or other mail server, so I tried this:
in /config/initializers/setup_email.rb
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 25
}
But I got "Connection refused - connect(2)" error message like following:
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/ruby-1.8.7-p330@myapp/gems/mail-2.2.15/lib/mail/network/delivery_methods/smtp.rb:127:in `deliver!'
/home/user1/.rvm/gems/ruby-1.8.7-p330@myapp/gems/mail-2.2.15/lib/mail/message.rb:1967:in `do_delivery'
/home/user1/.rvm/gems/ruby-1.8.7-p330@myapp/gems/mail-2.2.15/lib/mail/message.rb:228:in `deliver'
/home/user1/.rvm/gems/ruby-1.8.7-p330@global/gems/actionmailer-3.0.3/lib/action_mailer/base.rb:401:in `deliver_mail'
/home/user1/.rvm/gems/ruby-1.8.7-p330@global/gems/activesupport-3.0.3/lib/active_support/messages.rb:52:in `instrument'
/home/user1/.rvm/gems/ruby-1.8.7-p330@global/gems/activesupport-3.0.3/lib/active_support/messages/instrumenter.rb:21:in `instrument'
...
How to configure localhost for ActionMailer?
I searched on internet, it seems I MUST provide a username and password in the configuration, and set authentication option to some value, can I configure the ActionMailer without authentication, username and password? (because my app does not have a email account for login)
how to configure to make localhost email sending feature to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将其添加到您的环境中。rb:
Add this to your environment.rb:
在本地主机上,您应该使用 sendmail,一个好的开始就是 site
我知道来源很旧,但似乎仍然有效
on localhost you should be uusing sendmail, a good start would be this site
I know the source is old, but seems to be still valid
在本地主机上,您还可以使用 mailtrap。 关于 mailtrap 的博客文章。 此处有更多文档。就设置而言,我将其放入初始化程序中。
此方法对我有用。
On localhost you could also use mailtrap. blog post on mailtrap. There is more documentation here. As far as settings go, I put this in my initializer
This method worked for me.