setup_email.rb 中的 ActionMailer 配置有问题

发布于 2024-10-22 00:13:38 字数 2049 浏览 4 评论 0原文

我花了几天时间试图完成这项工作=>我想从我的应用程序 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往事随风而去 2024-10-29 00:13:38

将其添加到您的环境中。rb:

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

Add this to your environment.rb:

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default_charset = "utf-8"
原来是傀儡 2024-10-29 00:13:38

在本地主机上,您应该使用 sendmail,一个好的开始就是 site

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

我知道来源很旧,但似乎仍然有效

on localhost you should be uusing sendmail, a good start would be this site

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

I know the source is old, but seems to be still valid

定格我的天空 2024-10-29 00:13:38

在本地主机上,您还可以使用 mailtrap。 关于 mailtrap 的博客文章此处有更多文档。就设置而言,我将其放入初始化程序中。

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

此方法对我有用。

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

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

This method worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文