Hi, 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. Best Regards, Carl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ruby script/generate mailer customermailer models/customer_mail.rb: class CustomerMailer < ActionMailer::Base def welcome_message(sent_at = Time.now) @subject = ''CustomerMailer#welcome_message'' @body = {} @recipients = '''' @from = '''' @sent_on = sent_at @headers = {} @body["email"] = '''' end end views/customer_mailer/welcome_message.html.erb This will be your email message and now send it with this: customer_mail = CustomerMailer.create_welcome_message CustomerMailer.deliver(customer_mail) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the reply, I assume I need to define some configuration within the environment.rb for this to work? Regrds, Carl On Sep 30, 5:18 pm, heimdull <fre...-RCI/mp9mI1I6GGFevw1D/A@public.gmane.org> wrote:> ruby script/generate mailer customermailer > > models/customer_mail.rb: > > class CustomerMailer < ActionMailer::Base > > def welcome_message(sent_at = Time.now) > @subject = ''CustomerMailer#welcome_message'' > @body = {} > @recipients = '''' > @from = '''' > @sent_on = sent_at > @headers = {} > @body["email"] = '''' > end > end > > views/customer_mailer/welcome_message.html.erb > > This will be your email message > > and now send it with this: > > customer_mail = CustomerMailer.create_welcome_message > CustomerMailer.deliver(customer_mail)--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Oct-01 14:33 UTC
Re: Rails 2.0 Email (ActionMailer) Example
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 On Sep 30, 10:38 am, carlskii <carl.bou...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply, I assume I need to define some configuration > within the environment.rb for this to work? > > Regrds, > > Carl > > On Sep 30, 5:18 pm, heimdull <fre...-RCI/mp9mI1I6GGFevw1D/A@public.gmane.org> wrote: > > > ruby script/generate mailer customermailer > > > models/customer_mail.rb: > > > class CustomerMailer < ActionMailer::Base > > > def welcome_message(sent_at = Time.now) > > @subject = ''CustomerMailer#welcome_message'' > > @body = {} > > @recipients = '''' > > @from = '''' > > @sent_on = sent_at > > @headers = {} > > @body["email"] = '''' > > end > > end > > > views/customer_mailer/welcome_message.html.erb > > > This will be your email message > > > and now send it with this: > > > customer_mail = CustomerMailer.create_welcome_message > > CustomerMailer.deliver(customer_mail)--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Put this in the environment.rb file(I use the google smtp server so I had to install the action_mailer_tls plugin): config.action_mailer.raise_delivery_errors = false config.action_mailer.delivery_method = :smtp config.action_mailer.default_content_type = "text/html" config.action_mailer.default_url_options = { :host => "domainname.com" } config.action_mailer.smtp_settings = { :tls => true, :address => "smtp.gmail.com", :port => 587, :domain => "domainname.com", :authentication => :plain, :user_name => "username", :password => "password" } Here is a snip from new_question_message.html.erb I have: Question from..: <%= @question.name %><br /> Email..........: <%= @question.email %><br /> <% if @question.phonenumber -%> Phonenumber....: <%= @question.phonenumber %><br /> <% end -%> Subject........: <%= @question.subject %><br /> =========================================<br /> <%= @question.description %><br /> Then when I send this I have to pass the object: 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 http://railscasts.com/episodes/128-starling-and-workling Starling and Workling works great to offload the email delivery. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---