2017-06-19 105 views
2

我有我的用戶模型,用戶設計,我添加了一個郵件發送自己的電子郵件,當用戶註冊。當我運行我的代碼時,我沒有錯誤。在命令行中,它表示電子郵件已發送,但我什麼都沒有收到。你覺得是什麼原因呢。當新用戶註冊使用設計時,電子郵件不發送

我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的唯一文件。如果我必須添加更多文件或更改某些內容,請讓我知道。

我的命令行電子郵件發送確認:

+0

當您嘗試發送電子郵件時是否記錄了一些消息? –

+0

在命令行上,它顯示welcome_send.html.erb內容。 – Jasonbigg

+0

用日誌更新你的問題。隨着電子郵件的內容它可能會出現一個關於它的信息... –

回答

0

Rails Guide

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    address:    'smtp.gmail.com', 
    port:     587, 
    domain:    'example.com', 
    user_name:   '<username>', 
    password:    '<password>', 
    authentication:  'plain', 
    enable_starttls_auto: true 
} 

我想補充一點CONFIGS:

config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
config.action_mailer.raise_delivery_errors = true 
config.action_mailer.perform_deliveries = true 

和在Gmail中看到,如果你已經啓用2F權威性

+0

嘿蒂亞戈,我如何檢查我是否有2F身份驗證在Gmail? – Jasonbigg

+1

我想通了。謝謝您的幫助 – Jasonbigg

0

嘗試用:

config.action_mailer.smtp_settings = { 
    :address  => 'smtp.gmail.com', 
    :port   => 587, 
    :domain   => 'gmail.com', 
    :authentication => :login, 
    :user_name  => 'jasonbig', 
    :password  => 'I have entered my actual password here' 
    :enable_starttls_auto => true 
} 
+0

同樣的問題。你有看到他們的任何其他問題嗎?我的代碼中的 – Jasonbigg

+0

,郵件的正文究竟是如何發送的? (我在問這個,因爲我通過下面的教程得到了這段代碼) – Jasonbigg

+0

:authentication =>:plain, – Peter

相關問題