Chapter 13 - Email
Introduction
In this chapter, we'll learn how to send email using Rails, including configuration, email templates, delivery methods, and tests. In the process, we'll take an opportunity to revisit the user login page in order to add a screen name/password reminder, which will serve as our first concrete example of email. We'll then proceed to develop a simple email system to allow registered RailsSpace users to communicate with each other—an essential component of any social network. We'll see email again in Chapter 14, where it will be a key component in the machinery for establishing friendships between RailsSpace users.
Table of Contents
- 13.1 Action Mailer 389
- 13.1.1 Configuration 390
- 13.1.2 Password reminder 391
- 13.1.3 Linking and delivering the reminder 392
- 13.1.4 Testing the reminder 396
- 13.2 Double-blind email system 399
- 13.2.1 Email link 399
- 13.2.2 correspond and the email form 401
- 13.2.3 Email message 403
- 13.2.4 Testing double-blind email 406
Source Code
- Listing 13.1 config/environment.rb
- Listing 13.2 config/environment.rb
- Listing 13.3 config/environments/development.rb
- Listing 13.4 app/models/user_mailer.rb
- Listing 13.5 app/models/user_mailer.rb
- Listing 13.6 app/views/user_mailer/reminder.rhtml
- Listing 13.7 app/views/user/login.rhtml
- Listing 13.8 app/views/email/remind.rhtml
- Listing 13.9 app/controllers/email_controller.rb
- Listing 13.10 app/controllers/email_controller.rb
- Listing 13.11 test/unit/user_mailer_test.rb
- Listing 13.12 test/functional/email_controller_test.rb
- Listing 13.13 test/functional/email_controller_test.rb
- Listing 13.14 app/views/profile/_contact_box.rhtml
- Listing 13.15 app/controllers/profile_controller.rb
- Listing 13.16 app/views/profile/show.rhtml
- Listing 13.17 app/models/message.rb
- Listing 13.18 app/controllers/email_controller.rb
- Listing 13.19 app/views/email/correspond.rhtml
- Listing 13.20 app/models/user_mailer.rb
- Listing 13.21 app/views/user_mailer/message.rhtml
- Listing 13.22 test/fixtures/users.yml
- Listing 13.23 test/fixtures/specs.yml
- Listing 13.24 test/unit/user_mailer_test.rb
- Listing 13.25 test/functional/email_controller_test.rb
Errata
As of the first printing, these are the known corrections:
- p.403. Figure 13.3 The URL is wrong. At some point we changed the user names in the default data set from firstname_lastname to firstinitial_lastname, so Frank Capra's screen name is 'f_capra' and the URL should be http://localhost:3000/email/correspond/f_capra.