我正试图通过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
========
Run Code Online (Sandbox Code Playgroud)
我尝试从heroku控制台运行test_notification方法
>> Notifier.test_notification
Run Code Online (Sandbox Code Playgroud)
(这打印出一些日志信息..)
#<Mail:Message:279922420, Multipart: false, Headers: <from.., To, Subject, etc).
Run Code Online (Sandbox Code Playgroud)
但send_grid不会报告从我的帐户发出的任何邮件.我没有收到电子邮件.
我还尝试通过从/ home/index/controller调用test_notification来通过其他方式发送邮件,这将在访问应用程序的主页时发送.
===
class HomeController < ApplicationController
def index
Notifier.test_notification()
end
end
===
Run Code Online (Sandbox Code Playgroud)
统计信息不会报告发送的邮件.任何帮助是极大的赞赏.
谢谢!DS
尝试
Notifier.test_notification.deliver
Run Code Online (Sandbox Code Playgroud)
您需要调用deliver方法上的方法来实际发送消息.
http://guides.rubyonrails.org/action_mailer_basics.html
| 归档时间: |
|
| 查看次数: |
1618 次 |
| 最近记录: |