これまでに作った機能について簡単にまとめていく。
今回は、
開発環境でXserverからメールを送信する
前提条件
以下の情報が必要
Xserverのサーバー名、
ユーザー名(メールアドレス)、
パスワード
メイラーの作成
今回は、ユーザー登録時の通知メールを作成
$ rails g mailer EntryMailer
メール送信処理の作成
app/mailers/entry_mailer.rb
class EntryMailer < ApplicationMailer
def comfirm_mail(user)
@mail = user.mail
@user = user.name
mail to: "#{@mail}", subject: "ご登録が完了しました。"
end
end
メール本文の作成
app/views/entry_mailer/comfirm_mail.html.erb
<%= @user %>様のご登録が完了しました。
開発環境でのメールの設定
config/environments/development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => ENV['SERVER'],
:port => 587,
:user_name => ENV['USERNAME'],
:password => ENV['PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
以上で作成完了
