당신이 양식이 제출 한 후 사람 (또는 여러 사람을) 이메일을 보내려고 나에게 나타납니다. 아마도 그 양식의 정보를 데이터베이스에 저장하고있을 것입니다. 나는 당신이 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
나는 진심으로,이 대부가와 여행에 도움이되기를 바랍니다 및 스택 오버플로 커뮤니티에 오신 것을 환영합니다!감사합니다
,
로버트 Klubenspies이 당신의 진정한 아마존 키 아닌가요? – DAddYE
게시물 이후에 재설정했습니다. –