當我試圖確認郵件發送給用戶在我的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
有人可以幫我解決這個問題?
試着改變你的本地主機名'127.0 .0.1' – Pavan
我剛剛做到了,並且發生同樣的錯誤。 – yolo
嘗試此帖http://stackoverflow.com/questions/23300150/actionmailer-not-working-when-i-change-gmail-password/ 23300459#23300459 –