前提・実現したいこと
HerokuのSendgridアドオンを用いてRailsでユーザ作成時のメール認証機能を実装したいと考えています。
*当方RailsやHerokuを用いた開発経験が無く、手探り状態である事をご了承ください。
###やった事
postmanを用いて下記のJSON形式のユーザ情報を投げてテストを行いましたがエラーが出ました
JSON
1{ 2 "user":{ 3 "user_name":"****", 4 "email":"****@icloud.com", 5 "password":"rhcp21", 6 "password_confirmation":"rhcp21" 7 8 } 9}
発生している問題・エラーメッセージ
500:Internal Server Error
Net::SMTPFatalError: 550 Unauthenticated senders not allowed
エラーの詳細は以下に示します
匿名性を保持する為、*********@icloud.comと表記させて頂きます。
Started POST "/users" for ::1 at 2019-11-09 11:43:42 +0900 Processing by UsersController#create as */* Parameters: {"user"=>{"user_name"=>"****", "email"=>"****@icloud.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}} (1.7ms) BEGIN ↳ app/controllers/users_controller.rb:26 User Exists (2.5ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER($1) LIMIT $2 [["email", "****@icloud.com"], ["LIMIT", 1]] ↳ app/controllers/users_controller.rb:26 User Create (2.3ms) INSERT INTO "users" ("email", "password_digest", "user_name", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["email", "s houkitsuda@icloud.com"], ["password_digest", "$2a$12$muT2pAzq4SuIOzLea77.euur1wVwgoiV8JtgXmXDp7sESiPy8W1va"], ["user_name", "rhcp21"], ["created_at", "2019-11-09 11:43:42 .662938"], ["updated_at", "2019-11-09 11:43:42.662938"]] ↳ app/controllers/users_controller.rb:26 (7.9ms) COMMIT ↳ app/controllers/users_controller.rb:26 Rendering user_mailer/account_activation.html.erb within layouts/mailer Rendered user_mailer/account_activation.html.erb within layouts/mailer (7.9ms) UserMailer#account_activation: processed outbound mail in 15.4ms Completed 500 Internal Server Error in 328ms (ActiveRecord: 14.4ms) ActionView::Template::Error (undefined method `name' for #<User:0x00007fa790aef210>): 1: <h1>Sample App</h1> 2: 3: <p>Hi <%= @user.name %>,</p> 4: 5: <p> 6: Welcome to the Sample App! Click on the link below to activate your account: app/views/user_mailer/account_activation.html.erb:3:in `_app_views_user_mailer_account_activation_html_erb___3715546868340462326_70178831968000' app/mailers/user_mailer.rb:5:in `account_activation' app/models/user.rb:56:in `send_activation_email' app/controllers/users_controller.rb:27:in `create'
該当のソースコード
config/development.rb
ruby
1 config.action_mailer.raise_delivery_errors = true 2 config.action_mailer.delivery_method = :smtp 3 host ='https://aqueous-escarpment-97262.herokuapp.com' 4 config.action_mailer.default_url_options = { host: host } 5 ActionMailer::Base.smtp_settings = { 6 :address => 'smtp.sendgrid.net', 7 :port => '587', 8 :authentication => :plain, 9 :user_name => ENV['SENDGRID_USERNAME'], 10 :password => ENV['SENDGRID_PASSWORD'], 11 :domain => 'heroku.com', 12 :enable_starttls_auto => true
account_activation.html.erb
erb
1<h1>Sample App</h1> 2 3<p>Hi <%= @user.name %>,</p> 4 5<p> 6Welcome to the Sample App! Click on the link below to activate your account: 7</p> 8 9<%= link_to "Activate", edit_account_activation_url(@user.activation_token, 10 email: @user.email) %> 11
user_mailer.rb
ruby
1class UserMailer < ApplicationMailer 2 3 def account_activation(user)#5行 4 @user = user 5 mail to: user.email, subject: "Account activation" 6 end 7 8 # def password_reset(user) 9 # @user = user 10 # mail to: user.email, subject: "Password reset" 11 # end 12end 13
user.rb
ruby
1 # Sends activation email. 2 def send_activation_email 3 UserMailer.account_activation(self).deliver_now#56行 4 end
users_controller.rb
ruby
1 def create 2 @user = User.new(user_params) 3 # @users = params[:user].permit(:email, :password, :password_confirmation) 4 # User.new(@users) 5 6 if @user.save 7 @user.send_activation_email#27行 8 render json: { status: "Please check your email to activate your account." } 9 # flash[:info] = "Please check your email to activate your account." 10 # redirect_to root_url 11 render json: { status: 'success', data: @user } 12 else 13 render json: { status: 'error!', data: @user.errors } 14 end 15 end
sendgrid以外の部分でエラーが出ているようですが解決できなかったので投稿しました。
エラー解決に繋がる方法を教えていただくと助かります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。