簡體   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