Arun Agrawal’s Blog

Ruby on Rails Developer

Receiving Emails in Rails3

To receive email you have to write a method which needs to public in any subclass of ActionMailer::Base. The name should be receive. The method receive. will take a argument which is a Mail::Message obejct. An example here :
class EmailReceiver  < ActionMailer::Base

  def receive(email)
    person = Profile.find_by_email(email.to.first)
    person.emails.create(
      :subject => email.subject,
      :body => email.body
    )
  end
end
You can invoke this method on Mailer class to handle incoming email. You don’t have to implement the receive class method yourself, it is inherited from ActionMailer::Base.