我有我的用戶模型,用戶設計,我添加了一個郵件發送自己的電子郵件,當用戶註冊。當我運行我的代碼時,我沒有錯誤。在命令行中,它表示電子郵件已發送,但我什麼都沒有收到。你覺得是什麼原因呢。當新用戶註冊使用設計時,電子郵件不發送
我welcome_mailer:
class WelcomeMailer < ApplicationMailer
default :from => "[email protected]"
def welcome_send(user)
@user = user
mail to: "[email protected]", subject: "New user added", from: "[email protected]"
end
end
應用郵包:
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout 'mailer'
end
我的用戶模型:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
after_create :welcome_send
def welcome_send
WelcomeMailer.welcome_send(self).deliver
end
end
Welcome_mailer視圖(welcome_send.html.erb):
<h1>Hello, <%= @user.email %> has been added</h1>
development.rb在配置(也許錯誤是在SMTP設置):
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.delivery_method = :smtp
# these options are only needed if you choose smtp delivery
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 25,
:domain => 'gmail.com',
:authentication => :login,
:user_name => 'jasonbig',
:password => 'I have entered my actual password here'
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
end
這是我所涉及的ActionMailer的唯一文件。如果我必須添加更多文件或更改某些內容,請讓我知道。
我的命令行電子郵件發送確認:
當您嘗試發送電子郵件時是否記錄了一些消息? –
在命令行上,它顯示welcome_send.html.erb內容。 – Jasonbigg
用日誌更新你的問題。隨着電子郵件的內容它可能會出現一個關於它的信息... –