It appears to me that you're trying to email a person (or multiple people) after a form is submitted. Possibly you're saving information from that form to a database. I think that you are a little confused on how to use Padrino mailers. Allow me to clarify: In order to send an email, using Padrino's mailer functionality, with a full body of content, you must create a Padrino Mailer (I've outlined this below). Then you must configure that mailer so that you may pass variables to it when you call it. Those variables can then be used in the view, which your mailer renders into the email body before sending the email. This is one way of accomplishing what it appears you are trying to do and it is probably the most straight-forward. You can find more information about this procedd under "Mailer Usage" on the help page you provided in your question. I've outlined an example usage, tailored to what I believe your needs are, below.
Instructions
I threw together this code sample and tested it against my AWS account; it should work in production.
In your app/app.rb
file, include the following (you have already done so):
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
}
Then create a Mailer in app/mailers/affiliate.rb
:
# 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 'your-aws-sender-email@yoursite.com'
# Send the email to this person
to 'recipient-email@yoursite.com'
# 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
The Affiliate Mailer's send_email
view should be located in app/view/mailers/affiliate/send_email.erb
and look like this:
Name: <%= name %>
Email: <%= email %>
Finally, you can call your mailer from inside whatever method (and controller) you're accepting form submissions from. Be sure to replace the strings with actual form data. In this example, I used a POSTed create
action, which did not save any data (thus the strings with fake data):
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", "john.doe@example.com")
end
I sincerely hope that this helps you in your journey with Padrino, and welcome to the Stack Overflow community!
Sincerely,
Robert Klubenspies