加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 03:01:35 所属栏目:百科 来源:网络整理
导读:我正试图通过sendgrid从heroku上的rails应用程序发送邮件. 这是一个仅尝试发送测试电子邮件的独立应用程序.我没有错误,但邮件没有发送.非常感谢您的帮助. == config/environment.rb === ActionMailer::Base.smtp_settings = { :user_name = ENV['SENDGRID_US
我正试图通过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

解决方法

尝试

Notifier.test_notification.deliver

你需要在你的方法上调用deliver方法来实际发送消息.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读