简体   繁体   English

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

[英]Mailgun routes not connecting to incoming controller

I'm having a hard time finding a solution (almost 3 days) my code in incoming_controller.rb seems to be right, I tested it in the rails console and appears that the only problem is that when I send an email (from my gmail account) to my mailgun email, the routes I declare won't connect with my rails app, and I get warnings in my mailgun logs. 我很难找到一个解决方案(将近3天),我的incoming_controller.rb中的代码似乎是正确的,我在Rails控制台中对其进行了测试,似乎唯一的问题是当我发送电子邮件(从我的gmail帐户)到我的mailgun电子邮件,我声明的路线将无法与我的rails应用程序连接,并且我的mailgun日志中会收到警告。

What I'm trying to do is to allow users to send an email and convert the body content into a bookmark, and save it in the database, and the subject of the email as a topic. 我正在尝试做的是允许用户发送电子邮件并将正文内容转换为书签,并将其保存在数据库中,并将电子邮件主题作为主题。

Here is my routes.rb file: 这是我的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

My incoming_controller.rb file: 我的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

Topic belongs to User and has many bookmarks, User has many topics, Bookmark belongs to Topic. 主题属于用户并且具有很多书签,用户具有很多主题,书签属于主题。

Also, here's my mail.rb file: 另外,这是我的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

Note: mailgun works well with sending email confirmation instructions from Devise to the users, so it is configured correctly, what I can't do is to make mailgun to receive emails and store them in my rails db via parameters with the incoming_controller. 注意: mailgun可以很好地将来自Devise的电子邮件确认指令发送给用户,因此配置正确,我无法做的是使mailgun接收电子邮件并将其通过传入的控制器的参数存储在我的rails db中。

What am I doing wrong? 我究竟做错了什么?

My mailgun route is as follows: 我的mailgun路线如下:

Filter Expression: catch_all() 过滤器表达式: catch_all()

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

Here's the warning logs I get in mailgun when I send an email: 这是我发送电子邮件时在mailgun中收到的警告日志:

mailgun日志

Here's the project repository on github: https://github.com/bntzio/bookmark-this 这是github上的项目存储库: https : //github.com/bntzio/bookmark-this

Many thanks! 非常感谢!

Mailgun is receiving a 301 status code, being redirected to the https endpoint instead to the plain one. Mailgun正在接收301状态代码,该状态代码将重定向到https终结点而不是普通代码。 It seems that you have activated SSL but did not update the full route on the mailgun config to use it. 看来您已经激活了SSL,但没有更新mailgun配置上的完整路由来使用它。 You should update it to read like: 您应该将其更新为:

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

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

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