2017-05-08 4 views
0

Ich versuche willkommen Mail, wenn Benutzer registriert zu senden, aber alles in Ordnung scheint der gleiche Code i wie auch in anderen Projekt verwendet haben, aber die E-Mail nicht gesendet wird:Mail kann nicht in Schienen gesendet werden?

meine Anwendungsprotokolle:

Benutzer Laden (1.8ms) SELECT "Benutzer". * FROM "Benutzer" WHERE "Benutzer". "ID" = $ 1 LIMIT $ 2 [["ID", 14], ["LIMIT", 1]] [ActiveJob] [ActionMailer :: DeliveryJob] [3a0b9366-b50f-4934-8ca6-89303d1749bd] Ausführen von ActionMailer :: DeliveryJob von Async (Mailer) mit Argumente: "UserMailer", "user_mailer", "delivernow",

> [ActiveJob] [Action :: DeliveryJob]

[3a0b9366-b50f-4934-8ca6-89303d1749bd] Rendering user_mailer/user_mailer.html.erb innerhalb Layouts/Mailer [ActiveJob] [Action :: DeliveryJob] [3a0b9366-b50f-4934-8ca6-89303d1749bd]
Rendered user_mailer/user_mailer.html.erb innerhalb Layouts/Mailer (8.0ms) [ActiveJob] [Action :: DeliveryJob] [3a0b9366-b50f-4934-8ca6 -89303d1749bd] UserMailer # user_mailer: verarbeitet ausgehende Mail in 79,8 ms [ActiveJob] [ActionMailer :: DeliveryJob] [3a0b9366-b50f-4934-8ca6-89303d1749bd] Performed Action :: DeliveryJob von Async (Mailer) in 81.07ms

und meine environment.rb Datei:

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  => '[email protected]', 
    :password  => '********' 

    } 
end 

meine development.rb Datei:

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 

meine user_mailer. rb:

class UserMailer < ApplicationMailer 
    default from: '[email protected]' 

    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 

Mein 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> 

und meinen Benutzer Controller-Methode:

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 

Bitte sagen Sie mir, was ich falsch hier tue ich wirklich an ihm fest.

Antwort

1

unterhalb der Linie geändert:

UserMailer.user_mailer(@user).deliver_later 

zu

UserMailer.user_mailer(@user).deliver 

und überprüfen die, wenn Mail senden oder nicht.

Wenn Sie E-Mails im Hintergrund senden möchten, müssen Sie Gem delayed_job oder sidekiq zu Ihrer Gemfile hinzufügen.

Smtp Einstellung:

config.action_mailer.delivery_method =: smtp

config.action_mailer.smtp_settings = { 
     :address => "smtp.gmail.com", 
     :port => 587, 
     :domain => "gmail.com", 
     :user_name => "[email protected]", 
     :password => "xxxxxx", 
     :authentication => "plain", 
     :enable_starttls_auto => true 
    } 
+0

immer noch nicht funktioniert, ist es den HTML-Code in Server macht, aber ich in der E-Mail nicht erhalten haben: – aashi0001

+0

haben Sie testen in dev oder Produktion env? – puneet18

+0

Dev-Umgebung – aashi0001

Verwandte Themen