27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Real-world email<br />

Great! Now you have a way for users to toggle their watch status on any given ticket.<br />

Let’s make sure that everything is working by running rake cucumber:ok spec. You<br />

should see the following output:<br />

62 scenarios (62 passed)<br />

717 steps (717 passed)<br />

# and<br />

40 examples, 0 failures, 20 pending<br />

Everything is still A-OK, which is good to see. Let’s commit this change:<br />

git add .<br />

git commit -m "Add button so users can toggle<br />

watching on a ticket"<br />

git push<br />

You’ve now got a way that a user can start or stop watching a ticket. By watching a<br />

ticket, a user will receive an email when a comment is posted to the ticket. You’re<br />

doing great in theoretically testing email, but you haven’t yet configured your application<br />

to send out emails in the real world. Let’s do that now.<br />

12.3 Real-world email<br />

You’ve just created the beginnings of a way to send email in your application, but<br />

there’s still a part missing: the SMTP server that receives your mail objects and then<br />

sends them out to their recipients. You could spend a lot of time configuring one<br />

yourself, but many companies offer a free SMTP service, such as Gmail. 8 You’ll use a<br />

Gmail account to send out tests of your emails, and you can use Action Mailer to connect<br />

to this service.<br />

WARNING You wouldn’t use Gmail to send or receive your emails if you<br />

were running a much larger application, but rather another web service<br />

such as SendGrid. This is because Gmail has a limit of about 200 sent<br />

emails a day, and if there are 200 tickets updated in a single day then it’s<br />

goodbye email cap. Gmail is great for light email usage, but if you want to<br />

scale up your usage, SendGrid is one of the best options out there.<br />

Action Mailer has a setting that you can use to set up your SMTP connection:<br />

ActionMailer::Base.smtp_settings = {<br />

:username = "youraccount@example.com",<br />

:password = "yourpassword"<br />

...<br />

}<br />

Before you dive into setting this up, you’re going to need a feature to ensure that it<br />

always works. When you set up your application to send emails in the real world, it<br />

may work from the get-go, and you can test it manually by sending out emails in your<br />

8 SendGrid offers one too that you would use, but you’re going to need to receive emails next, and having a<br />

Gmail account will allow you to do that.<br />

333

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

Saved successfully!

Ooh no, something went wrong!