Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Heroku上使用MailGun实现ruby on rails应用程序_Ruby On Rails_Heroku_Mailgun - Fatal编程技术网

Ruby on rails 在Heroku上使用MailGun实现ruby on rails应用程序

Ruby on rails 在Heroku上使用MailGun实现ruby on rails应用程序,ruby-on-rails,heroku,mailgun,Ruby On Rails,Heroku,Mailgun,我正在尝试使用MailGun在我的RubyonRails应用程序中发送电子邮件,该应用程序托管在heroku上 我在heroku应用程序中添加了MailGun插件。我更新了我的config/environments/production.rb如下: config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :port => ENV['MAILGUN_

我正在尝试使用MailGun在我的RubyonRails应用程序中发送电子邮件,该应用程序托管在heroku上

我在heroku应用程序中添加了MailGun插件。我更新了我的
config/environments/production.rb
如下:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :port           => ENV['MAILGUN_SMTP_PORT'],
    :address        => ENV['MAILGUN_SMTP_SERVER'],
    :user_name      => ENV['MAILGUN_SMTP_LOGIN'],
    :password       => ENV['MAILGUN_SMTP_PASSWORD'],
    :domain         => 'mydomain.herokuapp.com', #mydomain actually contains the realvalue
    :authentication => :plain,
  }
我在app/mailers目录中创建了一个文件:

class ApplicationMailer < ActionMailer::Base
  default from: "myemail@gmail.com"

  def notify_user(user)
    puts "Going to send email!! to"
    puts user
    mail(to: user, subject: "Welcome!")
  end
end
我从另一个控制器打电话给notify_人员。然而在我的heroku日志中,通知人们!正在打印,之后什么都没有。我无法理解为什么它无法调用notify_user

我的通知用户功能是:

类ApplicationMailer结束

打电话给邮递员。稍后投递

ApplicationMailer.notify_user("xyz@gmail.com").deliver_later
此外,请确保使用您的邮枪帐户的详细信息

编辑:对
ApplicationMailer
的调用可能会出现异常。理想情况下,您应该在开发过程中对此进行故障排除,但如果需要,您可以将:
config.action\u mailer.raise\u delivery\u errors=true
添加到production.rb,以了解正在发生的情况


从另一个角度来看,不要使用print语句,而是查看诸如byebug和。它们可以为您节省大量的故障排除时间。

编辑了一些其他建议:)我在production.rb文件中添加了您提到的命令。我的heroku日志中没有任何错误。但是,在打印后调用邮件功能后,它看起来会失败,因为什么都没有。你能从应用程序发送电子邮件吗?您是否正在使用
稍后投递
呼叫邮递员?您是否在Heroku上设置了上述4个环境变量?你能确认执行了
notify\u user
吗?是的,我稍后会打电话给deliver\u。4个环境变量在Heroku中设置。是,通知用户已被呼叫。确定。执行了多少
notify\u user
?您能否发布
notify_user
的正文以及from production.rb(删除敏感位!)
ApplicationMailer.notify_user("xyz@gmail.com").deliver_later