質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

506閲覧

deviseを使用したメール送信ができず、困っています。

Sakurataro

総合スコア0

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/12/23 11:39

前提・実現したいこと

deviseのregistrationsコントローラをオーバーライドし、sign_upした後にActionMailerを使用してメールを送信したいです。(ThanksMailerを作成)

発生している問題・エラーメッセージ

sign_upはできているのですが、肝心なメールが送付できていません。
(メールの送付可否はletter_openerで確認済です。ターミナルは正常な挙動をしております。)
大変申し訳ございませんが、どなたかお力添えを頂ければと思います。

該当のソースコード

config/routes.rb Rails.application.routes.draw do devise_for :users, controllers: { registrations: "users/registrations" } root :to =>"homes#top" get "home/about"=>"homes#about" resources :books, only: [:index,:show,:edit,:create,:destroy,:update] if Rails.env.development? mount LetterOpenerWeb::Engine, at: "/letter_opener" end end
app/controllers/users/registrations_controller.rb class Users::RegistrationsController < Devise::RegistrationsController def create super do resource.update(confirmed_at: Time .now.utc) end end end
app/mailers/thanks_mailer.rb class ThanksMailer < ApplicationMailer attr_accessor :email, :title, :name def thanks_mail(email,title,name) @email = email @title = title @name = name mail to: @email, subject: "[テストメール#{@title}]" end end
app/views/mailer/application_mailer.erb class ApplicationMailer < ActionMailer::Base default from: 'no-replay@gmail.com' layout 'mailer' def complete_mail(user) @user = user @url = "http://localhost:3000/users/#{@user.id}" mail(subject: "COMPLETE join your address" ,to: @user.email) end end
app/views/mailers/thanks_mailer.erb class ThanksMailer < ApplicationMailer attr_accessor :email, :title, :name def thanks_mail(email,title,name) @email = email @title = title @name = name mail to: @email, subject: "[テストメール#{@title}]" end end
app/views/thanks_mailer/thanks_email.erb <p><%= @name %>さん</p> <p>登録が完了しました</p>
views/devise/mailer/confirmation_instructions.html <p>Welcome <%= @email %>!</p> <p>You can confirm your account email through the link below:</p> <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
config/environments/development.rb config.file_watcher = ActiveSupport::EventedFileUpdateChecker config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', domain: 'gmail.com', port: 587, user_name: 'xxxxxxx@gmail.com', password: 'xxxxxxxxxxx', authentication: 'plain', enable_starttls_auto: true } ActionMailer::Base.delivery_method = :letter_opener_web end

試したこと

development.rbのuser_name,passwordに環境変数を記入しましたが、上手くいきませんでした。

補足情報(FW/ツールのバージョンなど)

Rails5.2.4

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2020/12/26 05:22

logはどうなってますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問