#312 Sending HTML Email
HTML email can be difficult to code because any CSS should be made inline. Here I present a few tools for doing this including the premailer-rails3 and roadie gems.
- Download:
- source code Project Files in Zip (41.6 KB)
- mp4 Full Size H.264 Video (16 MB)
- m4v Smaller H.264 Video (9.19 MB)
- webm Full Size VP8 Video (8.07 MB)
- ogv Full Size Theora Video (23.3 MB)
Browse_code
Browse Source Code
Resources
terminal
rails new mailit cd mailit rails g mailer newsletter_mailer weekly bundle rails c
Gemfile
gem 'roadie' # or gem 'hpricot' gem 'premailer-rails3'
app/mailers/newsletter_mailer.rb
def weekly(email) mail to: email, subject: "RailsCasts Weekly" end
config/environments/development.rb
config.action_mailer.default_url_options = { host: "railscasts.com" }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "railscasts.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
rails console
NewsletterMailer.weekly("foo@example.com").deliver
loading