我正在構建一個具有帳戶激活功能的Web應用程序。我遵循Michael Hartl ROR教程,我沒有收到任何帳戶激活郵件到我的收件箱。我試圖在網上搜索如何驗證是否發送了一封電子郵件。就像應該有一個我們配置爲發送電子郵件的SMTP服務器?沒有找到有用的東西。有人可以幫忙嗎?如何驗證是否在Ruby on Rails Web應用程序中發送帳戶激活電子郵件
我account_activations_controller.rb
class AccountActivationsController < ApplicationController
def edit
user = User.find_by(email: params[:email])
if user && !user.activated? && user.authenticated?(:activation, params[:id])
user.activate
log_in user
flash[:success] = "Account activated!"
redirect_to user
else
flash[:danger] = "Invalid activation link"
redirect_to root_url
end
end
end
User_mailer.rb
class UserMailer < ApplicationMailer
def account_activation(user)
@user = user
mail to: user.email, subject: "Account activation"
end
end
application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout 'mailer'
end
development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :test
host = 'localhost:3000'
config.action_mailer.default_url_options = { :host=> host }
你需要激活帳號或配置發送電子郵件? – 2015-03-13 14:45:33
您應該添加一些關於您如何發送電子郵件的詳細信息,而不是假設每個人都熟悉教程。任何電子郵件發送方法都需要您執行一些配置才能使其工作。你做到了嗎? – 2015-03-13 14:56:21
@MaxWilliams對不起,我已經更新了我的配置詳細問題 – Sandeep 2015-03-13 15:13:51