Screencast: ActionMailer and Gmail
September 24, 2009This screencast shows how to set up a Ruby on Rails application to send email with ActionMailer and Gmail.
Ruby 1.8.7 and Rails 2.2.1 or later versions are required to use TLS (required for Gmail SMTP) without a plugin. If you use older versions of either Ruby or Rails, try a plugin like action_mailer_optional_tls.
I've improved the quality of the video for this screencast. A high quality version is available on YouTube via the link above.
I'd like to give a big thanks to Nebyoolae for providing the intro sound!
Here is the code from the screencast:
# config/environments/development.rb config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :enable_starttls_auto => true, :address => 'smtp.gmail.com', :port => 587, :authentication => :plain, :domain => 'myapp.com', :user_name => 'username@gmail.com', :password => 'password' }
# app/models/notifier.rb class Notifier < ActionMailer::Base def gmail_message subject 'Message via Gmail' recipients 'youremail@address.com' from 'webmaster@address.com' sent_on Time.now end end
# app/views/notifier/gmail_message.text.plain.erb Hello, You are receiving this email via Gmail!
<!-- app/views/notifications/index.html.erb --> <a href="/notifications/create">Send</a> a message via Gmail!
# app/controllers/notifications_controller.rb class NotificationsController < ApplicationController def index end def create Notifier.deliver_gmail_message flash[:notice] = 'Your message has been sent.' redirect_to root_path end end
# config/routes.rb ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.root :controller => 'notifications', :action => 'index' end
Comments
September 24, 2009
These screencasts are looking hella professional, mang. And that Nebyoolae fellow is awesome.
November 30, 2009
Hi,
I've tried this, and it doesn't seem to error. Should it work from localhost?
December 17, 2009
just for anyone else, yes it does work from localhost
February 19, 2010
same here, tried this and doesn't work, no flash notice 'Your message has been sent.' and no new mail in gmail
Comments are closed
Comments are automatically closed 2 weeks after publication. If you still have something to say about the article, feel free to contact me.