Rails3標準では、「ちゃんと使える」Action Mailerがあるので、ぜひ使おう
config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :enable_starttls_auto => true, :address => 'smtp.gmail.com', :port => 587, :domain => 'gmail.com', :authentication => :plain, :user_name => '自分のメアド@gmail.com', :password => '自分のパスワード' }
# config.action_mailer.raise_delivery_errors = false
rails g mailer NoticeMailer sendmail_confirm
#coding: utf-8 class NoticeMailer < ActionMailer::Base default from: "from@example.com" def sendmail_confirm(user) @user = user mail to: "送信先のメアド", subject: "テストメール" end end
default from: "from@example.com", cc: "cc@example.com"
ユーザ名:<%= @user.username %> メールアドレス:<%= @user.email %> URL:<%= url_for( :host => 'www.example.com', :controller => 'books', :action => 'index' ) %>
def send_mail user = User.find(1) @mail = NoticeMailer.sendmail_confirm(user).deliver render :text => "送信できた!" end