htmlruby-on-railsemailherokupostmark

Where to put mailer class in my Ruby on Rails app?


I added postmark to my Ruby On rails app. I followed the steps from the page https://devcenter.heroku.com/articles/postmark#sending-emails-in-ruby-on-rails-3-x . Now I need to add the following code:

class SuperMailer < ActionMailer::Base

  def email
    from       "test@domain.com"
    subject    "Hello"
    recipients "myemail@domain.com"
    tag        "big-bang"   end

end

However, I do not know where to add this class, and how to use it. I Do I add it in the application.rb file in the module of my app?

And how do I use this class to send the email on after submit (i.e. when someone presses Submit)? I wrote the form with the submit button in an html file in my static_pages under app > views Do I do the following?

<form name="contactform" method="post" > ...

Solution

  • The Action Mailer Rails Guide Is the best most comprehensive guide on this - it's easy to read and well worth your time.

    As to your question - it's waaay too vague to answer (you have asked multiple questions here, not just one)- but in this case, all the answers are in the Rails Guide.

    but for one: you put mailers in the app/mailers directory and two: you have to set up a controller action for your form-action that calls eg: SuperMailer.email.deliver

    but really: read the guide it will answer your questions