Skip to Main Content
Learning Rails
book

Learning Rails

by Simon St. Laurent, Edd Dumbill
November 2008
Beginner content levelBeginner
448 pages
12h 25m
English
O'Reilly Media, Inc.
Content preview from Learning Rails

Sending Complex HTML Email

Once you start sending HTML email, odds are good that you’ll want to start sending pretty HTML email, complete with graphics. You can include HTML links to resources on your site, but many mail programs block those, because they’re potential violations of privacy. Instead, it often makes more sense to send the graphics as part of the email message, as a multipart attachment.

Warning

There are fewer and fewer people who deeply object to HTML email, but there are still a lot of people who get annoyed by huge messages that take a long time to download. If you wouldn’t feel comfortable sending a message to a relative on dial-up, you probably shouldn’t send it to anyone, unless they’ve specifically requested something they know is large.

ActionMailer can handle most of the logistics for this, using the same tools shown earlier, but it needs one additional library to make it work. From the command line, or the Heroku Gems & Plugins Manager, add the InlineAttachment gem:

gem install InlineAttachment

One of the nicer features of multipart email is that it can include a plain-text version as well as HTML and graphics, so app/views/awards/show.html.erb can revert to the checkbox-free version shown earlier in Example 17-5. Similarly, because the awards_controller no longer needs to evaluate the checkbox, app/controllers/awards_controller.rb can revert to the version shown in Example 17-2. (The code for this example is in ch17/students012.)

Most of the work needed to send ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Rails 5

Learning Rails 5

J. Mark Locklear, Eric J Gruber, Barnabas Bulpett
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao
Ruby on Rails® Bible

Ruby on Rails® Bible

Timothy Fisher

Publisher Resources

ISBN: 9780596154943Supplemental ContentErrata