【发布时间】:2016-01-18 18:44:16
【问题描述】:
当应用程序发送电子邮件时出现此错误:
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 587):
app/controllers/incidents_controller.rb:66:in `block in create'
app/controllers/incidents_controller.rb:62:in `create'
Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.4ms)
Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.9ms)
Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms)
Rendered /home/jeremymontesinos/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (16.8ms)
Cannot render console with content type multipart/form-dataAllowed content types: [#<Mime::Type:0x000000033b4ef0 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x000000033b4bf8 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x000000033ad330 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]
我的开发.rb:
config.action_mailer.default_url_options = {:host => "localhost"}
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
adress: 'auth.smtp.1and1.fr',
port: '587',
user_name: 'foo@bar.fr',
password: 'password',
authentication: :plain,
enable_starttls_auto: true}
config.action_mailer.raise_delivery_errors = true
环境.rb:
# Load the Rails application.
require File.expand_path('../application', __FILE__)
ActionMailer::Base.default :content_type => "text/html"
# Initialize the Rails application.
Rails.application.initialize!
我的控制器(我发送电子邮件的命令):
def create
@incident = Incident.new(incident_params)
@incident.user_id ||= current_user.id
@incident.incident_state_id_for_user = 1
@incident.incident_state_id_for_tech = 1
respond_to do |format|
if @incident.save
@response = Response.new(content: "Incident créé par #{current_user.name} #{current_user.surname}", incident_id: @incident.id, sender_id: @incident.user_id)
@response.save!
AppMailer.incident_created.deliver_now
format.html { redirect_to @incident, notice: 'Incident crée.' }
format.json { render :show, status: :created, location: @incident }
else
format.html { render :new }
format.json { render json: @incident.errors, status: :unprocessable_entity }
end
end
end
App_mailer.rb:
类 AppMailer 还有application_mailer.rb: 所以我使用 LinuxMint 17.2、Server Puma on rails、rails 4.2.3 ... 编辑:我尝试使用 telnet auth.smtp.1and1.fr 587 ping 服务器,它可以工作 我尝试将端口更改为:25 和 465,但它不起作用 default from: "foo@bar.fr"
def incident_created()
mail(to: "bar@baz.com", subject: "Succefull !", body: "You're really cool!")
end
end
class ApplicationMailer < ActionMailer::Base
default from: "foo@bar.fr" #Here is a fake mail adress
layout 'mailer'
end
【问题讨论】:
-
它看起来像是一个错误的主机名 (
localhost) 而不是端口问题... -
adress?不应该是address? -
天哪!谢谢!
标签: ruby-on-rails ruby ruby-on-rails-4