· 1 min read

Screencast: ActionMailer in Rails 3

Download:

Download (27.5 MB, 12:20) Alternative Download für iPod & Apple TV (16.3 MB, 12:20)

Resourcen:

Quellcode:

[bash] rails mailit cd mailit rails g scaffold user name:string email:string rake db:migrate rails g mailer user_mailer bundle install [/bash]

[ruby] # config/initializers/setup_mail.rb ActionMailer::Base.smtp_settings = { :address => “smtp.gmail.com”, :port => 587, :domain => “railscasts.com”, :user_name => “railscasts”, :password => “secret”, :authentication => “plain”, :enable_starttls_auto => true }

ActionMailer::Base.default_url_options[:host] = “localhost:3000” Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?

# app/mailers/user_mailer.rb class UserMailer < ActionMailer::Base default :from => “ryan@railscasts.com” def registration_confirmation(user) @user = user attachments[“rails.png”] = File.read(”#{Rails.root}/public/images/rails.png”) mail(:to => ”#{user.name} <#{user.email}>”, :subject => “Registered”) end end

# users_controller.rb UserMailer.registration_confirmation(@user).deliver

# Gemfile gem “mail”, “2.1.3”

# lib/development_mail_interceptor.rb class DevelopmentMailInterceptor def self.delivering_email(message) message.subject = ”#{message.to} #{message.subject}” message.to = “ryan@railscasts.com” end end [/ruby]

[html] <%= @user.name %>,

Thank you for registering!

Edit profile: <%= edit_user_url(@user) %>

<%= @user.name %>,

Thank you for registering!

<%= link\_to "Edit profile", edit\_user\_url(@user) %>

\[/html\]
Back to Blog