5

sendgrid 経由で heroku の ruby​​ on rails アプリからメールを送信しようとしています。これは、テスト メールの送信のみを試みるスタンドアロン アプリです。エラーは出ませんが、メールは送信されません。あなたの助けに感謝します。

== config/environment.rb === 
    ActionMailer::Base.smtp_settings = { 
    :user_name => ENV['SENDGRID_USERNAME'], 
    :password => ENV['SENDGRID_PASSWORD'], 
    :domain => ENV['SENDGRID_DOMAIN'], 
    :address => "smtp.sendgrid.net", 
    :port => 587, 
    :authentication => :plain, 
} 
===

==== config/environments/production.rb === 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.raise_delivery_errors = true 
=====

== app/models/notifier.rb == 
    class Notifier < ActionMailer::Base

    include SendGrid 

    default from: "abc@yahoo.com" 
    #sendgrid_category :use_subject_lines 
    #sengrid_enable :ganalytics, :opentrack

    def test_notification 
      mail(:to => "xyz@gmail.com", :subject => "mail from heroku") 
      puts("Sent mail from notifier") 
   end 

   end 
======== 

heroku コンソールから test_notification メソッドを実行してみました

>> Notifier.test_notification 

(これにより、いくつかのログ情報が出力されます..)

#<Mail:Message:279922420, Multipart: false, Headers: <from.., To, Subject, etc). 

しかし、send_grid は私のアカウントから送信されたメールを報告しません。メールが届きません。

また、アプリのホームページにアクセスしたときに送信される /home/index/controller から test_notification を呼び出して、別の方法でメールを送信しようとしました。

=== 
class HomeController < ApplicationController 
def index 
Notifier.test_notification() 
end

end

===

統計は、メールが送信済みであることも報告しません。どんな助けでも大歓迎です。

ありがとう!DS

4

2 に答える 2

7

試す

Notifier.test_notification.deliver

deliver実際にメッセージを送信するには、メソッドでメソッドを呼び出す必要があります。

http://guides.rubyonrails.org/action_mailer_basics.html

于 2011-11-02T07:21:07.463 に答える
0

Heroku に SendGrid アドオンがあることを確認してください。

user_name => ENV['SENDGRID_USERNAME'], 
:password => ENV['SENDGRID_PASSWORD'], 
:domain => ENV['SENDGRID_DOMAIN'], 

詳細は、sendgrid のユーザー名、パスワード、およびドメインである必要があります

于 2015-06-18T04:05:00.547 に答える