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: "[email protected]" def sendmail_confirm(user) @user = user mail to: "送信先のメアド", subject: "テストメール" end end
default from: "[email protected]", cc: "[email protected]"
ユーザ名:<%= @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