邮件未发送:使用Ruby on Rails在heroku上发送sendgrid

时间:2011-11-02 05:14:12

标签: heroku sendgrid

我正在尝试通过sendgrid从heroku上的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

2 个答案:

答案 0 :(得分:6)

Notifier.test_notification.deliver

您需要在方法上调用deliver方法来实际发送消息。

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

答案 1 :(得分:0)

确保你的Heroku有一个SendGrid插件。代码

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

详细信息应该是您的sendgrid用户名,密码和域

相关问题