无法在铁轨中发送邮件?

时间:2017-05-08 10:09:52

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我试图在用户注册时发送欢迎邮件,但一切似乎都很好 我在不同项目中使用的代码相同,但邮件未发送:

我的申请日志:

  

用户负载(1.8ms)SELECT"用户"。* FROM"用户"用户"。" id"   = $ 1 LIMIT $ 2 [[" id",14],[" LIMIT",1]] [ActiveJob] [ActionMailer :: DeliveryJob] [3a0b9366-b50f-4934-8ca6-89303d1749bd ]   从Async(邮件程序)执行ActionMailer :: DeliveryJob   参数:" UserMailer"," user_mailer"," deliver_now",

     

> [ActiveJob] [ActionMailer :: DeliveryJob]

     

[3a0b9366-b50f-4934-8ca6-89303d1749bd]渲染   布局/邮件中的user_mailer / user_mailer.html.erb [ActiveJob]   [ActionMailer :: DeliveryJob] [3a0b9366-b50f-4934-8ca6-89303d1749bd]
  在layouts / mailer中呈现user_mailer / user_mailer.html.erb   (8.0ms)[ActiveJob] [ActionMailer :: DeliveryJob]   [3a0b9366-b50f-4934-8ca6-89303d1749bd] UserMailer#user_mailer:   处理79.8ms的出站邮件[ActiveJob]   [ActionMailer :: DeliveryJob] [3a0b9366-b50f-4934-8ca6-89303d1749bd]   在81.07ms内从Async(邮件程序)执行ActionMailer :: DeliveryJob

和我的environment.rb文件:

require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!
Rails.application.configure do

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

  if Rails.env.development? || Rails.env.test?
    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  elsif Rails.env.production?
    config.action_mailer.default_url_options = {:host => ENV['HOST']}
  end

  config.action_mailer.smtp_settings = {   
    :openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,      
    :enable_starttls_auto => true,  #this is the important stuff!

    :address        => 'smtp.gmail.com',

    :port           => 587,
    :authentication => :plain,
    :user_name      => 'ravichem12@gmail.com',
    :password       => '********'

   } 
end

我的development.rb文件:

Rails.application.configure do

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports.
  config.consider_all_requests_local = true

  # Enable/disable caching. By default caching is disabled.
  if Rails.root.join('tmp/caching-dev.txt').exist?
    config.action_controller.perform_caching = true

    config.cache_store = :memory_store
    config.public_file_server.headers = {
      'Cache-Control' => 'public, max-age=172800'
    }
  else
    config.action_controller.perform_caching = false

    config.cache_store = :null_store
  end

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.perform_caching = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Suppress logger output for asset requests.
  config.assets.quiet = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true

  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport::EventedFileUpdateChecker


  config.action_mailer.delivery_method = :smtp
end

我的user_mailer.rb:

class UserMailer < ApplicationMailer
    default from: 'support@lokavidya.com'

  def user_mailer(user)
    @user = user
    if Rails.env.development? || Rails.env.test?
        @url  = 'http://localhost:3000/login'       
    elsif Rails.env.production?
        @url  = 'http://client-development-env.fr4s6529gr.us-west-2.elasticbeanstalk.com/login'
    end
    mail(to: @user.email, subject: 'Welcome to Lokavidya')
  end
end

我的user_mailer.html.erb:

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1><%= Welcome to Lokavidya %> <%= @user.name %></h1>
    <p>
      <%= Welcome To Lokavidya %> <%= @user.email %>.<br>
    </p>
    <h3>
      <% if Rails.env.development? || Rails.env.test? %>
        <%#= verify_users_url(@user.confirmation_link) %>
        <a href="http://localhost:3000/users/verify?link=<%= @user.confirmation_link%>">

      <% elsif Rails.env.production? %>
        <a href="http://client-development-env.fr4s6529gr.us-west-2.elasticbeanstalk.com/users/verify?link=<%= @user.confirmation_link%>">
      <% end %>

      <%= "Click The Above Link to Verify Your Account" %>
      </a>
    </h3>
    <p><%= "Thanks For Joining Lokavidya" %></p>
  </body>
</html>

和我的用户控制器方法:

def create
    @user = User.new(user_params)
    @user.confirmation_link = confirmation_link!
    @user.uuid = unique_id!
    if @user.password == @user.password_confirmation
      if @user.save
        UserMailer.user_mailer(@user).deliver_later
        msg  = {:status => 200, :uuid => @user.uuid, :message => "User created Succesfully" }
        return render :json => msg
      else
        render json: @user.errors, status: :unprocessable_entity
      end
    end
  end

请告诉我我在这里做错了什么我真的被困在了。

0 个答案:

没有答案