Does anybody have a simple Rails 2.1 working example of creating an
email from a simple Web form and sending it via ActionMailer? Most of
the examples I've found so far all seem to be Rails 1.x based and
don't work with Rails 2.x.
Hiemdull,
I find this thread wonderfully useful and interesting...is there a
chance you could show an example of the views/customer_mailer/
welcome_message.html.erb ?
Is customer_mailer a controller also?
I am grateful for a comprehensive example.
Thank you,
Kathleen
mail = CustomerMailer.create_new_question_message(@question)
CustomerMailer.deliver(mail)
customer_mailer is not a controller its a actionmailer and it lives in
the /app/models directory
When you use the ruby script/generate mailer customermailer command it
creates that for you.
So the steps would be:
- Create the mailer with generate mailer
- Add a mailer action like welcome_message
- Setup your environment.rb with the correct smtp setup
- add the deliver action to your action in your controller (Imprtant
is to use CustomerMailer.create_ <- )
That should be all you need.
If you don't want to wait for the email to be sent (Sometimes the app
waits a second or 3 to send an email which does not make for a snappy
interface) Watch this #128 Starling and Workling - RailsCasts
Starling and Workling works great to offload the email delivery.