繁体   English   中英

Mailgun路由未连接到传入控制器

[英]Mailgun routes not connecting to incoming controller

我很难找到一个解决方案(将近3天),我的incoming_controller.rb中的代码似乎是正确的,我在Rails控制台中对其进行了测试,似乎唯一的问题是当我发送电子邮件(从我的gmail帐户)到我的mailgun电子邮件,我声明的路线将无法与我的rails应用程序连接,并且我的mailgun日志中会收到警告。

我正在尝试做的是允许用户发送电子邮件并将正文内容转换为书签,并将其保存在数据库中,并将电子邮件主题作为主题。

这是我的routes.rb文件:

Rails.application.routes.draw do
  devise_for :users

  get 'welcome/index'
  get 'welcome/about'

  root to: 'welcome#index'

  post :incoming, to: 'incoming#create'
end

我的incoming_controller.rb文件:

class IncomingController < ApplicationController
  skip_before_action :verify_authenticity_token, only: [:create]

  def create
    @user = User.find_by(email: params[:sender])
    @topic = Topic.find_by(title: params[:subject])

    @url = params["body-plain"]

  if @user.nil?
    @user = User.new(email: params[:sender], password: "temp0rary_passw0rd")
    @user.skip_confirmation!
    @user.save!
  end

  if @topic.nil?
    @topic = @user.topics.create(title: params[:subject])
  end

  @bookmark = @topic.bookmarks.create(url: @url)

  head 200
  end
end

主题属于用户并且具有很多书签,用户具有很多主题,书签属于主题。

另外,这是我的mail.rb文件:

ActionMailer::Base.smtp_settings = {
  port:              587, 
  address:           'smtp.mailgun.org',
  user_name:         ENV['MAILGUN_SMTP_LOGIN'],
  password:          ENV['MAILGUN_SMTP_PASSWORD'],
  domain:            'appfc266c436eb04ebaae05a3f3f8ad7e49.mailgun.org',
  authentication:    :plain,
  content_type:      'text/html'
}
ActionMailer::Base.delivery_method = :smtp

# Makes debugging *way* easier.
ActionMailer::Base.raise_delivery_errors = true

注意: mailgun可以很好地将来自Devise的电子邮件确认指令发送给用户,因此配置正确,我无法做的是使mailgun接收电子邮件并将其通过传入的控制器的参数存储在我的rails db中。

我究竟做错了什么?

我的mailgun路线如下:

过滤器表达式: catch_all()

动作: forward(“ http://bookmark-this.herokuapp.com/incoming/ ”)

这是我发送电子邮件时在mailgun中收到的警告日志:

mailgun日志

这是github上的项目存储库: https : //github.com/bntzio/bookmark-this

非常感谢!

Mailgun正在接收301状态代码,该状态代码将重定向到https终结点而不是普通代码。 看来您已经激活了SSL,但没有更新mailgun配置上的完整路由来使用它。 您应该将其更新为:

Actions: forward("https://bookmark-this.herokuapp.com/incoming/")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM