Errno :: ECONNREFUSED:连接被拒绝-动作邮件程序的connect(2) [英] Errno::ECONNREFUSED: Connection refused - connect(2) for action mailer

查看:1166
本文介绍了Errno :: ECONNREFUSED:连接被拒绝-动作邮件程序的connect(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很久以来我一直在使用rails。现在,我在ActionMailer中面临一个小问题。我想在用户注册后发送电子邮件以确认其注册。
我可以在开发模式中发送电子邮件,但是在生产模式中发送电子邮件。

异常 Errno :: ECONNREFUSED:连接被拒绝-每当调用 deliver 方法时,connect(2)都会到来。

我编写了以下代码。

我的SMTP配置如下:

config.action_mailer.default_url_options = {:host => localhost:3000}

I have been working with rails since a long. Now I am facing a small issue in the ActionMailer. I want to send an email when user gets registered to confirm his registration. I am able to send email in the development mode but where as not in the production mode.
the exception Errno::ECONNREFUSED: Connection refused - connect(2) is coming everytime when deliver method is called.
I have written the following code.
My SMTP config looks:
config.action_mailer.default_url_options = { :host => "localhost:3000" }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.smtp_settings = {   
    :openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,      
    :ssl => true,
    :enable_starttls_auto => true,  #this is the important stuff!
    :address        => 'smtp.xxxx.xxx',
    :port           => xxx,
    :domain         => 'xxxxxx',
    :authentication => :plain,
    :user_name      => 'xxxxxxx@xxx.xxx',
    :password       => 'xxxxxxxxx'
  }

在控制器中,我编写了以下内容:

In the controller, I have written the following:

def confirm_registration_in_c       
 @user = User.find_by_email(asdf123@gmail.com)
 if @user
      UserMailer.confirm_registration(@user).deliver            
 end
end

在我的user_mailer.rb中:

In my user_mailer.rb :

class UserMailer < ActionMailer::Base
  default from: "from@example.com"

  def confirm_registration(user)
   @user = user
   @user_name = @user.name       
   email = @user.email 
   mail(:to => email, :subject => "Reset your password")
  end
end

我可以在本地主机上以开发模式发送电子邮件,但无法发送电子邮件


有人可以帮我吗?

I am able to send email in the development mode in my local host, but I am not able to send the email in the dedicated server.
Can anybody help me please?

推荐答案

在我的情况下,当我尝试通过发送电子邮件的Rails应用程序教程时遇到了类似的问题,Heroku日志不断告诉我

In my situation, I encountered similar problems when I was trying to making through a sending-email Rails app tutorial, the Heroku logs kept telling my that

......

Errno :: ECONNREFUSED(连接被拒绝-connect(2)for 本地主机端口25):

......

在将我的代码与作者的代码进行比较之后,我发现我没有设置我的Act config / environments / production.rb 文件中的ionMailer配置。

After I compared my code with author's code, I got to find out that I had not setup my ActionMailer configurations in the config/environments/production.rb file.

然后我意识到我只有 config / environment / development.rb 已配置为发送电子邮件,但我的 config / environments / production.rb 尚未配置。

Then I came to realized that I just had my config/environments/development.rb configured for sending-email, but I had not done it for my config/environments/production.rb.

因此,当应用的行为在开发和生产之间有所不同时,您可以进行检查。

So you may check it when your app's behavior difers between development and production.

这篇关于Errno :: ECONNREFUSED:连接被拒绝-动作邮件程序的connect(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆