Rails 邮件发送:getaddrinfo:名称或服务未知

Posted

技术标签:

【中文标题】Rails 邮件发送:getaddrinfo:名称或服务未知【英文标题】:Rails mailer deliver : getaddrinfo: Name or service not known 【发布时间】:2014-06-28 19:02:45 【问题描述】:

当我尝试在我的 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

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

【问题讨论】:

尝试将您的本地主机名更改为127.0.0.1 我刚刚做了,我遇到了同样的错误.. 试试这个帖子***.com/questions/23300150/… 又是同样的错误.. 【参考方案1】:

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

【讨论】:

【参考方案2】:

语法错误 - 你在 :from 之后忘记了 =&gt;

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

【讨论】:

现在我解决了这个问题,我遇到了另一个错误:getaddrinfo: Name or service not known at this line SwarmNotifier.confirmvisitor(@member).deliver in swarm_notifier.rb 您尚未在本地主机中配置邮件服务器或您的系统没有 Internet 连接。 我认为配置 setup_mail.rb 就足够了吗?我应该安装 sendmail 吗? 我如何知道我的应用程序是否可以访问互联网? 那将是一个单独的问题

以上是关于Rails 邮件发送:getaddrinfo:名称或服务未知的主要内容,如果未能解决你的问题,请参考以下文章

Python 发送邮件 socket.gaierror: [Errno 11004] getaddrinfo failed

Rails 电子邮件名称标签

rails server error `initialize': getaddrinfo: Name or service not known (SocketError)

rails 服务器无法启动; getaddrinfo:提供节点名或服务名,或未知(SocketError)

Rails 4: Carrierwave/AWS - Excon::Errors::SocketError / getaddrinfo: nodename or servname provided

如何更改从我的应用程序发送的电子邮件中显示的名称?