27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This chapter covers<br />

� Sending email with Action Mailer and the mail gem<br />

� Subscribing via email to specific events within the system<br />

� Connecting to a real-world email server to send emails<br />

� Receiving emails using Action Mailer<br />

312<br />

Sending email<br />

In the previous chapter, you implemented tagging for your application, which<br />

allows users to easily categorize and search for tickets.<br />

In this chapter, you’ll begin to send emails to your users. When a user signs up<br />

to Ticketee, they use their email address as a way for the system to uniquely identify<br />

them. You then verify that the address is valid by sending the user a confirmation<br />

email. With a user’s validated email address, you’re able to send them updates for<br />

important events in the system, such as a ticket being updated.<br />

Back in chapter 6, you changed a setting for the authentication engine Devise<br />

that would send a confirmation email to a new user when they signed up. To test this<br />

setting, you used a gem called email_spec, which only tested that the emails were<br />

delivered in a test environment, and not in the real world. This is how Action Mailer<br />

(the Rails component responsible for email) acts 1 during a test environment.<br />

1 It defaults to not truly sending out the emails, but rather keeping track of them in a variable that you can<br />

access by using ActionMailer::Base.deliveries, or by using the methods found in email_spec.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!