私はときに、ユーザー登録歓迎メールを送信しようとしていますが、すべては私も別のプロジェクトで使用してきたが、メールが送信されません同じコード 罰金だ:メールをレールに送信できません。
私のアプリケーションログ:
ユーザー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]
レンダリング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].07ms
と私environment.rbにファイル内の非同期から出演actionmailerの:: DeliveryJob(メーラー):
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
私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: '[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
私の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
は、私がここで間違ってやっている私は本当にそれで立ち往生しています何を教えてください。
UserMailer.user_mailer(@user).deliver
に
UserMailer.user_mailer(@user).deliver_later
とメールが送信またはいないかどうかを確認:
まだ働いていない、それはサーバ内のHTMLコードをレンダリングするが、私は、メールで受信しませんでした:あなたは、DEVや生産ENVに – aashi0001
テストしていますか? – puneet18
dev環境 – aashi0001