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.To 代码中有一个 SendGrid 插件

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

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

于 2015-06-18T04:05:00.547 回答