【问题标题】:Mailgun routes not connecting to incoming controllerMailgun 路由未连接到传入控制器
【发布时间】:2015-06-09 06:04:24
【问题描述】:

我很难找到解决方案(将近 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

Topic属于User,有很多书签,User有很多topic,Bookmark属于Topic。

另外,这是我的 ma​​il.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 通过参数传入_controller。

我做错了什么?

我的mailgun路线如下:

过滤表达式: catch_all()

操作: forward("http://bookmark-this.herokuapp.com/incoming/")

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

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

非常感谢!

【问题讨论】:

  • 当您发送电子邮件时,mailgun 日志会显示什么内容?

标签: ruby-on-rails email mailgun bloc.io


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 2019-06-26
    • 1970-01-01
    • 2023-03-27
    相关资源
    最近更新 更多