Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Rails mailer deliver : getaddrinfo: Name or service not known

rails4 mailer gmail

  • Please log in to reply
1 reply to this topic

#1 mouad

mouad

    Passenger

  • Members
  • 2 posts

Posted 11 May 2014 - 01:47 PM

When I'm trying to send a confirmation mail to users in my rails application, it puts me this error in my browser:

SocketError (getaddrinfo: Name or service not known)

Highlighting this line:

SwarmNotifier.confirmvisitor(@member).deliver

Here the swarm_notifier.rb in mailer:

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

The member_controller.rb which call those confirmation methods is like:

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

My setup_mail.rb look like this:

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

Can someone help me fix this ?



#2 mouad

mouad

    Passenger

  • Members
  • 2 posts

Posted 16 May 2014 - 03:10 PM   Best Answer

I finally found the magic solution: The firewall of my school blocked my smtp connection...







Also tagged with one or more of these keywords: rails4, mailer, gmail

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users