0

Following the instructions here: http://www.padrinorb.com/guides/padrino-mailer

I have the delivery method added on the app.rb file:

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  
  }

But via the generation through Padrino and the Mailer generation, I do not have the recommended "sessions" controller in which this should belong:

post :create do
  email(:from => "tony@reyes.com", :to => "john@smith.com", :subject => "Welcome!",     :body=>"Body")
end

Am I missing something?

I have the form for a basic data collection at an office and just need an email to be sent to 5 recipients with all the form fields in the message body.

Thanks

1 Answers1

1

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

Robert Klubenspies
  • 438
  • 1
  • 7
  • 21