2012-08-31 3 views
0

레일즈 3.2.3 응용 프로그램이 잘 작동하고 작성한 메일 메시지를 전달하기 때문에 등록 확인과 비밀번호는 메일 메시지를 잊어서 새 비밀번호를 설정합니다.레일스 3 메일이 작동하지 않으나 메일이 작동하지 않습니다.

그러나 메일 알림을 전달하려는 다른 장소가 있습니다.

이것은 내 Notifier 모델입니다.

# encoding: utf-8 
class Notifier < ActionMailer::Base 
    default from: "[email protected]" 
    default to: "[email protected]" 

    def new_post_submitted(post) 
    @post = post 
    mail(subject: "Anúncio enviado: #{@post.title}") 
    end 

    def new_message(message) 
    @message = message 
    mail(subject: "Mensagem de contato: #{@message.subject}") 
    end 

end 

와 컨트롤러가 호출

def create 
    @message = Message.new(params[:message]) 

    if @message.valid? 
    Notifier.new_message(@message).deliver 
    redirect_to(root_path, :notice => "Obrigado. Sua Mensagem enviada com sucesso") 
    else 
    flash.now.alert = "Por favor preencha todos os campos." 
    render :new 
    end 
end 

로그 출력이 전달 된 말한다 :

Started POST "/contato" for 187.57.102.168 at 2012-08-31 11:28:51 +0900 
Processing by ContactController#create as HTML 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"TVdmDYCA4x3JVi+9pMcpY7OSU/P1lE9enLiFJlK9W1M=", "message"=>{"name"=>"kleber", "email"=>"[email protected]", "subject"=>"teste", "body"=>"hello there"}, "commit"=>"Enviar"} 
    Rendered notifier/new_message.html.erb (0.1ms) 

Sent mail to [email protected] (152ms) 
Redirected to http://www.domain.com/ 
Completed 302 Found in 158ms (ActiveRecord: 0.0ms) 

그리고 내 config/production.rb 파일에 다음과 같은 구성.

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = { 
    :address => "localhost", 
    :port => 25, 
    :domain => "domain.com", 
    :authentication => :login, 
    :user_name => "[email protected]", 
    :password => "mypassword", 
    :enable_starttls_auto => false 
} 

여기에 무슨 일이 일어나고 있는지 실마리가 있습니까?

+1

스팸 이메일을 확인하셨습니까? –

+0

예, 거기에는 아무 것도 없습니다. –

+0

및 시스템 로그 폴더? (/ var/log, 즉 /var/log/mail.log) 경고/오류가 있습니까? –

답변

1

다음은 내 production.rb 파일에서 작동하는 설정입니다.

ActionMailer::Base.smtp_settings = { 
    :address => 'mail.domain.com', 
    :port => 587, 
    :domain => 'domain.com', 
    :authentication => :login, 
    :user_name => '[email protected]', 
    :password => 'password' 
    } 

delivery_method를 지정해야하는지 확실하지 않습니까?

ActionMailer::Base.delivery_method = :smtp 

구성에 문제가 없으며 모든 것이 올바르게 작동합니다.

레일 API http://api.rubyonrails.org/ ActionMailer 섹션에는 전송 오류를 설정할 수있는 옵션이 있습니다.

raise_delivery_errors - Whether or not errors should be raised if the email fails to be delivered. 

문제를 추가로 해결할 수 있습니다.

0

먼저, 환경 파일에서 다른 곳으로 배달을 해제하지 않았는지 확인합니다

# the default is true anyway, so if you don't see it anywhere in 
# the file, you should be okay 
config.action_mailer.perform_deliveries = true 

나는 옆 전달 방법을 변경하려고 할 것이다 :sendmail 또는 :file 중 하나에. sendmail을 시스템 (적어도 개발 시스템)에 설치하고 구성한 경우 보내시는 전자 메일을 받아야합니다. 한때 센트 메일이 OS X의 박스에서 처리되었다는 사실을 알고 놀랐습니다. CentOS에서도 같은 것을 찾을 수 있을지 확신하지 못합니다.

sendmail이 없거나 구성하지 않으려면 :file 배달 방법을 사용하여 전자 메일을 파일 시스템의 파일로 덤프하십시오.

전자 메일이 센드 메일이나 파일을 통해 전달되지 않으면 스택에서 문제가 있음을 알게됩니다. 배달을 수행하는 경우 문제는 SMTP 구성입니다. 알려진 Gmail 서버 (예 : Gmail 계정)를 사용해보십시오. 작동하는 경우 ActionMailer가 아닌 localhost에서 실행중인 SMTP 서버에 문제가 있음을 알 수 있습니다.

관련 문제