2012-05-23 5 views
0

에서 양식 제출에 보내기 위해서는 어떻게 :당신은 아마존 SES 여기의 지시에 따라 대부가

class OscarAffiliate < Padrino::Application 
    register Padrino::Rendering 
    register Padrino::Mailer 
    register Padrino::Helpers 

    enable :sessions 

    set :delivery_method, :smtp => { 
    :address    => "email-smtp.us-east-1.amazonaws.com", 
    :port     => 587, 
    :user_name   => 'AKIAIQ5YXCWFKFXFFRZA', 
    :password    => 'AqMNMFecKSYR/TRu8kJgocysAL5SmIUsu2i8u/KAfeF/', 
    :authentication  => :plain, 
    :enable_starttls_auto => true 
    } 

그러나 경유 :

http://www.padrinorb.com/guides/padrino-mailer 내가 전달 방법은 app.rb 파일을 추가 한

post :create do 
    email(:from => "[email protected]", :to => "[email protected]", :subject => "Welcome!",  :body=>"Body") 
end 

암 I없는 뭔가를 : 대부가 및 메일러 생성을 통해 세대는,이 속한해야하는 권장 "세션"컨트롤러를 가지고 있지 않은거야?

나는 사무실에서 기본 데이터 수집을위한 양식을 가지고 있으며 메시지 본문의 모든 양식 필드를 가진 5 명의 수신자에게 전자 메일을 보내야합니다.

감사

+0

로버트 Klubenspies이 당신의 진정한 아마존 키 아닌가요? – DAddYE

+0

게시물 이후에 재설정했습니다. –

답변

1

당신이 양식이 제출 한 후 사람 (또는 여러 사람을) 이메일을 보내려고 나에게 나타납니다. 아마도 그 양식의 정보를 데이터베이스에 저장하고있을 것입니다. 나는 당신이 Padrino 메일러를 사용하는 방법에 약간 혼란 스럽다고 생각합니다. 내가 명확히 할 수있게 해주세요 : Padrino의 메일러 기능을 사용하여 전자 메일을 보내려면 전체 본문과 함께 Padrino Mailer를 만들어야합니다 (아래에서 간략히 설명했습니다). 그런 다음 메일러를 호출 할 때 변수를 전달할 수 있도록 메일러를 구성해야합니다. 이러한 변수는보기에서 사용될 수 있으며 메일러는 전자 메일을 보내기 전에 전자 메일 본문으로 렌더링합니다. 이것이 당신이하려고하는 것을 성취하는 한 가지 방법이며 아마도 가장 직접적 일 것입니다. 이 절차에 대한 자세한 내용은 질문에 제공된 help page의 "메일러 사용법"을 참조하십시오. 아래에 귀하의 필요가 있다고 생각하는 것에 맞춘 예제 사용법을 설명했습니다.


지침

내가 함께이 코드 샘플을 던지고 내 AWS 계정에 대해 그것을 테스트; 그것은 생산에서 작동해야합니다.

app/app.rb 파일에서

는 (당신은 아직 한) 다음과 :

set :delivery_method, :smtp => { 
    :address    => 'email-smtp.us-east-1.amazonaws.com', 
    :port     => 587, 
    :user_name   => 'SMTP_KEY_HERE', 
    :password    => 'SMTP_SECRET_HERE', 
    :authentication  => :plain, 
    :enable_starttls_auto => true 
} 

그런 다음 app/mailers/affiliate.rb에 메일러를 만듭니다 제휴 메일러의 send_email보기가 위치해야

# Defines the mailer 
DemoPadrinoMailer.mailer :affiliate do 
    # Action in the mailer that sends the email. The "do" part passes the data you included in the call from your controller to your mailer. 
    email :send_email do |name, email| 
    # The from address coinciding with the registered/authorized from address used on SES 
    from '[email protected]' 
    # Send the email to this person 
    to '[email protected]' 
    # Subject of the email 
    subject 'Affiliate email' 
    # This passes the data you passed to the mailer into the view 
    locals :name => name, :email => email 
    # This is the view to use to redner the email, found at app/views/mailers/affiliate/send_email.erb 
    render 'affiliate/send_email' 
    end 
end 

app/view/mailers/affiliate/send_email.erb에 있고 다음과 같이 보입니다.

Name: <%= name %> 
Email: <%= email %> 

마지막으로 양식 제출을 수락하는 모든 방법 (및 컨트롤러) 내부에서 우편물을 호출 할 수 있습니다. 문자열을 실제 양식 데이터로 바꾸십시오. 이 예에서, 내가 어떤 데이터 (가짜 데이터 따라서 문자열)를 저장하지 않은 게시 된 create 조치를 사용 :

post :create do 
    # Deliver the email, pass the data in after everything else; here I pass in strings instead of something that was being saved to the database 
    deliver(:affiliate , :send_email, "John Doe", "[email protected]") 
end 

나는 진심으로,이 대부가와 여행에 도움이되기를 바랍니다 및 스택 오버플로 커뮤니티에 오신 것을 환영합니다!감사합니다

,

관련 문제