2011-03-14 3 views
2

레일스 3을 사용 중이며 이메일 전송 기능을 구현 중입니다. 내 코드를 내 구성이 올 경우 잘 모르겠지만, 현재 위치 :rails 3 이메일 전송 문제

우편물/user_mailer.rb

class UserMailer < ActionMailer::Base 
    default :from => "[email protected]" 

    def send_to(user) 
    @user = user 
    subject='welcome !' 
    mail(:to=>'[email protected]', :subject=>subject, :content_type => "text/html") 
    mail.deliver 
    end 
end 

컨트롤러 :

def CarsController < BaseController 
    ... 
    def register_finish 
    UserMailer.send_to(user) 
    end 

end 

설정/환경. rb

config.action_mailer.delivery_method = :smtp 

config.action_mailer.smtp_settings = { 
    :address => "smtp.googlemail.com", 
    :port => 532, 
    :arguments => '-i' 
    :enable_starttls_auto => true 
    } 

    config.action_mailer.perform_deliveries = true 
    config.action_mailer.raise_delivery_errors = true 

내 컨트롤러가 'register_finish'함수를 호출하고 사용자에게 전자 메일을 보내려고 할 때 항상 Timeout :: Error (실행 만료 됨) 오류 메시지가 표시됩니다. 그 이유는 무엇입니까 ??

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = {...} 
:

나는 어떤 사람들은 설정/초기화/setup_email.rb의 구성을 정의하고 내가 설정/enviroment.rb 및 사용을 구성하면서

ActionMailer::Base.delivery_method = :smtp 
ActionMailer::Base.smtp_settings = { ...} 

를 사용했다

또한 'UserMailer'내부에서 컨트롤러를 호출하는 동안 일부 사람들이 컨트롤러에서 "전달"메서드를 호출하는 것을 보았습니다.

내 질문 :

내 구현과 내가 인터넷에서 발견 구현 위의 다른 방법의 차이는 무엇
  1. .

  2. 왜 시간 초과 오류가 발생합니까?

답변

4

나는 또한 내 SMTP 서버로 Gmail을 사용하고 있는데이 코드

ActionMailer::Base.smtp_settings = { 
    :address    => "smtp.gmail.com", 
    :port     => 587, 
    :domain    => "domain.pl", 
    :user_name   => "username", 
    :password    => "password", 
    :authentication  => "plain", 
    :enable_starttls_auto => true 
} 

를 포함 initiliazers에 가산 setup_email.rb을했습니다 그리고 그것은 나를 :)

편집 작동

다른 서버를 사용하고 있습니다. 설정을 시도해 보셨습니까?

+0

콘솔이 이메일이 전송되었습니다 보여줍니다 나를 위해 잘 작동하지만, 메일 박스 수신하지 않습니다 ... 그것을 위해 – Mellon

+0

대기, 그것은 잠시 후에 올 수 있습니다) –

+0

아직도받은 :(하지만 주셔서 감사하지 :) – Mellon

2

시간 초과 오류는 일부 인증 오류가 있음을 의미합니다.

이 라인은 더 이상 필요하지 않습니다 :

ActionMailer::Base.delivery_method = :smtp 

초기화에 smtp_settings을 설정 adviceable된다.당신이 개발 시스템에 그것을 사용하는 경우

이 구성은 Gmail에서 작동합니다 :

ActionMailer::Base.smtp_settings = { 
:enable_starttls_auto => true, 
:address => 'smtp.gmail.com', 
:port => 587, 
:domain => 'your_domain', 
:authentication => :plain, 
:user_name => 'your_gmail_username', 
:password => 'your_gmail_password' 
} 

편집

당신이 개발 시스템에 대한 추가 할 수 있습니다

:

ActionMailer::Base.default_url_options[:host] = "localhost:3000" 

Very good railscast on subject

+0

config/enviroment.rb 또는 config/initializer/setup_email.rb 파일에 넣으십시오. – Mellon