Question

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 ?

Was it helpful?

Solution

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

OTHER TIPS

Syntax error - You forgot => after :from

mail :to => @member.email, :from => "myappadress@gmail.com", :subject => "Player registration confirmation"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top