Section 9.0. Introduction


9.0. Introduction

Contributed by: Dae San Hwang

Most people receive dozens, if not hundreds, of emails every day. Many of those emails are not sent by real people. They are automatically generated and sent by computer programs. For example, when you sign up for a newsletter, that newsletter is sent by software; when you place an order online, your confirmation message is generated by the shopping application; if you need to reset a password, the operation probably involves several automatically generated email messages.

A full-fledged web application framework therefore needs the ability to generate and send email messages. In Rails, the Action Mailer framework has this responsibility. To send email with Action Mailer, you first need to create a custom mailer class. This mailer class contains constructor methods for the different messages your application needs to send. The layout of your email message is handled by Action View, in a manner similar to RHTML templates. Each constructor has a corresponding Action View template that determines the content of the email message.

Once your mailer class and template files are in place, it is trivial to compose and send email. You only need to provide some String values for the email headers, and some objects for populating the Action View template.

In addition to sending email messages, a web framework needs the ability to respond to incoming mail. Action Mailer can handle incoming email. No, it does not talk to POP3 or IMAP mail servers directly. It requires external helpers to fetch email and feed the raw email text into a receive method you define. The recipes in this chapter show the three different ways to retrieve emails and forward them to the receive method of your mailer class.




Rails Cookbook
Rails Cookbook (Cookbooks (OReilly))
ISBN: 0596527314
EAN: 2147483647
Year: 2007
Pages: 250
Authors: Rob Orsini

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net