2014-01-20 2 views
4

Ruby on Rails를 사용하고 있는데, Mandrill을 사용하여 메일을 송수신하는 방법을 가르쳐 주시겠습니까?Mandrill을 사용하여 메일을 보내고받는 방법?

내 문제는 사용자가 텍스트를 입력하고 제출을 누르면 내 메일에 메시지를 보내려고합니다. 설명서를 읽었지만 이해가되지 않습니다.

은 production.rb 같은 내 development.rb입니다

ActionMailer::Base.smtp_settings = { 
    :port =>   '587', 
    :address =>  'smtp.mandrillapp.com', 
    :user_name =>  '[email protected]', 
    :password =>  's82SlRM5dPiKL8vjrJfj4w', 
    :domain =>   'heroku.com', 
    :authentication => :plain 
} 
ActionMailer::Base.delivery_method = :smtp 

user_mailer.rb : 같은

def index 
    UserMailer.welcome.deliver 
end 

내 로그 파일보기 :

class UserMailer < ActionMailer::Base 
    default from: "[email protected]" 
    def welcome 
    mail(to: "[email protected]", subject: "Welcome", body: "Have a nice day") 
    end 
end 

및 컨트롤러

이 :

Started GET "https://stackoverflow.com/users/" for 127.0.0.1 at 2014-01-21 16:14:10 +0700 
Processing by UsersController#index as HTML 

Sent mail to [email protected] (2008.0ms) 
Date: Tue, 21 Jan 2014 16:14:10 +0700 

From: [email protected] 

To: [email protected] 

Message-ID: <[email protected]> 

Subject: Welcome 

Mime-Version: 1.0 

Content-Type: text/plain; 

charset=UTF-8 

Content-Transfer-Encoding: 7bit 



Have a nice day 
    Rendered text template (0.0ms) 
Completed 200 OK in 2018ms (Views: 1.0ms | ActiveRecord: 0.0ms) 

답변

5

먼저 mandrill.com에서 계정을 만들어야합니다.

로그인 한 후 통합 유형 (SMTP 또는 API)을 선택하십시오. SMTP는 대부분의 경우에 당신을위한 것입니다.

SMTP를 클릭하고 API 키를 만듭니다.

는 그런 다음 development.rb 또는 production.rb 파일에 다음 줄을 추가

config.action_mailer.smtp_settings = { 
    :port =>   '587', 
    :address =>  'smtp.mandrillapp.com', 
    :user_name =>  ENV['MANDRILL_USERNAME'], 
    :password =>  ENV['MANDRILL_APIKEY'], 
    :domain =>   'domain.com', 
    :authentication => :plain 
} 

을 모두 기본적으로 있다고. 이제 Mandrill으로 이메일을 보낼 수 있습니다.

편집 또한

환경에 추가하려고이있는 경우 배달 오류를 배달을 수행하고 인상이 줄을 파일. 또한 default_url_options를 추가 - 개발 로컬 호스트에서 : 3000, 생산 heroku.com에

config.action_mailer.perform_deliveries = true 
config.action_mailer.raise_delivery_errors = true 
config.action_mailer.default_url_options = { host: "localhost:3000" } 
앱을 다시 시작

테스트하기 전에

편집 2

당신은 ActionMailer 버튼을 제출에 이메일을 보내려면 클릭하면 해당 컨트롤러의 동작을 생성하기 위해 UserMailer.welcome.deliver을 이동해야합니다.

def create 
    if @object.save 
    UserMailer.welcome.deliver 
    else 
    render "new" 
    end 
end 
+0

감사합니다. 시도했지만 아직 메일을받지 못했습니다. 'default : "[email protected]" def welcome_email mail ([email protected], 제목 : "내 웹 사이트에 오신 것을 환영합니다") end' – user3214298

+0

올바른 사용자 이름과 apikey를 사용하셨습니까? 일시적으로'ENV []'를 삭제하고 그냥 일반 문자열을 삽입하십시오. 또한 환경 .rb 파일에'config.action_mailer.delivery_method = : smtp'가 있는지 확인하십시오. –

+0

도움을 주셔서 감사합니다. 그러나 여전히 작동하지 않습니다 ... 내 파일 내용을 게시했습니다 ... – user3214298

관련 문제