2014-05-11 79 views
3

當我試圖確認郵件發送給用戶在我的Rails應用程序,它使我這個錯誤在我的瀏覽器:Rails的郵件程序提供:的getaddrinfo:產品名稱或服務不知道

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 => "[email protected]", :subject => "Player registration confirmation" 
    end 

    def confirmadmin(member) 
    @member = member 

    mail :to => @member.email, :from => "[email protected]", :subject => "Administrator registration confirmation" 
    end 

    def confirmvisitor(member) 
    @member = member 

    mail :to => @member.email, :from => "[email protected]", :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 => "[email protected]", 
    :password => "mypass", 
    :authentication => "plain", 
    :enable_starttls_auto => true 
} 

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

有人可以幫我解決這個問題?

+0

試着改變你的本地主機名'127.0 .0.1' – Pavan

+0

我剛剛做到了,並且發生同樣的錯誤。 – yolo

+0

嘗試此帖http://stackoverflow.com/questions/23300150/actionmailer-not-working-when-i-change-gmail-password/ 23300459#23300459 –

回答

3

我終於找到了神奇的解決方案忘記=>:我校的防火牆擋住了我的SMTP連接...

0

語法錯誤 - 你以後:from

mail :to => @member.email, :from => "[email protected]", :subject => "Player registration confirmation" 
+0

現在,我解決了這個問題我有另一個錯誤:getaddrinfo:在這一行中未知的名稱或服務SwarmNotifier.confirmvisitor(@member).deliver in swarm_notifier.rb – yolo

+0

您尚未在本地主機中配置郵件服務器,或者您的系統沒有Internet連接。 – emaillenin

+0

我認爲配置setup_mail.rb就夠了嗎?我應該安裝sendmail嗎? – yolo

相關問題