2016-07-29 4 views
1

私はメールを送ることができるヘルロにレールアプリを持っています。通知用の電子メールを送信するための新しい機能を追加しました。 私はこれをHerokuログに記録しますが、電子メールは送信されません。Ruby on Rails 5アプリでメールが配信されないのはなぜですか?

2016-07-29T19:57:58.895499+00:00 app[web.1]: [ActiveJob] [NotificationBroadcastJob] [40c7b651-3c5d-4308-b8b5-49a142d2930f] Rendered notifications_mailer/new_message.html.erb (226.4ms) 
2016-07-29T19:57:58.895630+00:00 app[web.1]: [ActiveJob] [NotificationBroadcastJob] [40c7b651-3c5d-4308-b8b5-49a142d2930f] NotificationsMailer#new_message: processed outbound mail in 246.0ms 
2016-07-29T19:57:58.895741+00:00 app[web.1]: [ActiveJob] [NotificationBroadcastJob] [40c7b651-3c5d-4308-b8b5-49a142d2930f] Performed NotificationBroadcastJob from Async(default) in 377.85ms 

これはこれは私が/ notifications_broadcast_job.rb

class NotificationBroadcastJob < ApplicationJob 
. 
. 
    NotificationsMailer.new_message(personal_message).deliver_now 

Iアプリ/ジョブでnew_messageアクションを呼び出す方法です

class NotificationsMailer < ApplicationMailer 
    def new_message(message) 
    @message = message 
    mail(to: message.receiver.email, subject: 'You have a new message') 
    end 
end 

notifications_mailer.rb /ルビーファイルアプリ/メーラーnotifications_mailerですSendgridアドオンを使用してください。これはproduction.rbのものです

config.action_mailer.perform_caching = false 

    # Ignore bad email addresses and do not raise email delivery errors. 
    # Set this to true and configure the email server for immediate delivery to raise delivery errors. 
    # config.action_mailer.raise_delivery_errors = false 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.delivery_method = :smtp 
    host = 'www.abcdef.com' 
    config.action_mailer.default_url_options = { host: host } 
    ActionMailer::Base.smtp_settings = { 
    :address  => 'smtp.sendgrid.net', 
    :port   => '587', 
    :authentication => :plain, 
    :user_name  => ENV['SENDGRID_USERNAME'], 
    :password  => ENV['SENDGRID_PASSWORD'], 
    :domain   => 'www.abcdef.com', 
    :enable_starttls_auto => true 
    } 

これは私がワーカーdynosを持っていない私のdevelopment.rb

# Don't care if the mailer can't send. 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.delivery_method = :test 
    host = 'rails-tutorial-suai.c9.io' 
    config.action_mailer.default_url_options = { host: host } 
    config.action_mailer.perform_caching = false 

です。これは私のProcfileです。

web: bundle exec puma -C config/puma.rb 

誰でもお手伝いできますか?ありがとう

+0

sendgridやその他のメールサービスを設定しましたか? –

+0

@SergioTulentsevはい。これらの設定で質問を更新しました。 – LovingRails

+0

ワーカーdynoをスピンアップしましたか?あなたのprocfileには何がありますか? – M00B

答えて

1

あなたのコールサイトNotificationsMailerclass NotificationBroadcastJob < ApplicationJobにあります。つまり、ActiveJobを使用しています。 Mailer docsから: アダプター非同期(async):

アクティブなジョブのデフォルトの動作を経由してジョブを実行することです。したがって、今すぐdeliver_laterを使用して、電子メール を非同期で送信することができます。アクティブジョブのデフォルトアダプタは、 インプロセススレッドプールを使用してジョブを実行します。 の開発/テスト環境には適しています。外部インフラストラクチャを必要としないので、 ですが、 の再起動時に保留中のジョブを廃棄するため、生産には適していません。永続的なバックエンドが必要な場合は、持続的なバックエンド(Sidekiq、Resque、 など)を持つ アクティブなジョブアダプタを使用する必要があります。

したがって、Sidekiq/Resqueのようなジョブバックエンドなしで動作します。 Herokuに設定されているようなものがあると仮定すると、少なくとも1つのワーカーdynoをスピンアップし、作業プロセスをProcfileに登録する必要があります。ここで

docs on Herokuですが、要旨は次のとおりです。あなたはRedisSidekiqのようなキューのバックエンド、あなたのProcfile(例えばworker: bundle exec sidekiq -q default)に登録されたワーカープロセス、およびHerokuの(例えば$ heroku ps:scale web=1 worker=1)の上にスピンアップワーカープロセスが必要になります。

これはまた、Herokuアプリケーションでsendgridアドオンをプロビジョニングし、必要なConfig Varsを追加したことを前提としています。

A similar SO answer

関連する問題