#312 Sending HTML Email
Jan 02, 2012 | 5 minutes | Tools
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 codeProject Files in Zip (41.6 KB)
- mp4Full Size H.264 Video (16 MB)
- m4vSmaller H.264 Video (9.19 MB)
- webmFull Size VP8 Video (8.07 MB)
- ogvFull Size Theora Video (23.3 MB)
Resources
terminal
rails new mailit
cd mailit
rails g mailer newsletter_mailer weekly
bundle
rails c
rails new mailit cd mailit rails g mailer newsletter_mailer weekly bundle rails c
Gemfile
gem 'roadie'
# or
gem 'hpricot'
gem 'premailer-rails3'
gem 'roadie' # or gem 'hpricot' gem 'premailer-rails3'
app/mailers/newsletter_mailer.rb
def weekly(email)
mail to: email, subject: "RailsCasts Weekly"
end
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"]
}
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
NewsletterMailer.weekly("foo@example.com").deliver

