Rails邮件程序提供:getaddrinfo:名称或服务未知

时间:2014-05-11 10:55:06

标签: ruby-on-rails mailer

当我尝试向我的rails应用程序中的用户发送确认邮件时,它会在浏览器中显示此错误:

SocketError (getaddrinfo: Name or service not known)

突出显示以下行:SwarmNotifier.confirmvisitor(@member).deliver

邮件中的swarm_notifier.rb:

class SwarmNotifier < ActionMailer::Base

  def confirmplayer(member)
    @member = member

    mail :to => @member.email, :from => "myappadress@gmail.com", :subject => "Player registration confirmation"
  end

  def confirmadmin(member)
    @member = member

    mail :to => @member.email, :from => "myappadress@gmail.com", :subject => "Administrator registration confirmation"
  end

  def confirmvisitor(member)
    @member = member

    mail :to => @member.email, :from => "myappadress@gmail.com", :subject => "Visitor registration confirmation"
  end
end

调用这些确认方法的member_controller.rb如:

 def create
    @member = Member.new(member_params)

    respond_to do |format|
      if @member.save
    case @member.role
    when "visitor"
          SwarmNotifier.confirmvisitor(@member).deliver
    when "administrator"
          SwarmNotifier.confirmadmin(@member).deliver
    when "player"
          SwarmNotifier.confirmplayer(@member).deliver
        end
        format.html { redirect_to @member, notice: 'Member was successfully created.' }
        format.json { render :show, status: :created, location: @member }
      else
        format.html { render :new }
        format.json { render json: @member.errors, status: :unprocessable_entity }
      end
    end
  end

我的setup_mail.rb看起来像这样:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => "stmp.gmail.com", 
  :port  => 587,
  :domain  => 'localhost',
  :user_name => "myappadress@gmail.com",
  :password => "mypass",
  :authentication => "plain",
  :enable_starttls_auto => true
}

ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true

有人可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:3)

我终于找到了神奇的解决方案:我学校的防火墙阻止了我的smtp连接...

答案 1 :(得分:0)

语法错误 - 您在=>

之后忘记了:from
mail :to => @member.email, :from => "myappadress@gmail.com", :subject => "Player registration confirmation"