2015-04-04 43 views
1

我很难找到一个解决方案(近3天)我的代码在incoming_controller.rb似乎是正确的,我在轨道控制台测试它,似乎是唯一的问题是,当我(从我的Gmail帐户)发送电子邮件到我的mailgun电子邮件时,我声明的路由将不会与我的rails应用程序连接,并且在我的mailgun日志中收到警告。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 

主题所属的用户,有许多书签,用户有很多话题,Bookmark属于Topic。

而且,这里是我的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从设计发送电子邮件确认指令到用户的效果很好,所以它的配置是否正确,我所能不要做的是让mailgun接收电子邮件并通过incoming_controller的参数将它们存储在我的rails db中。

我在做什么错?

我mailgun路线如下:

筛选表达式: CATCH_ALL()

操作:前进( “http://bookmark-this.herokuapp.com/incoming/”)

这里的警告日志我mailgun时得到我发送电子邮件:

mailgun logs

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

非常感谢!

+0

当您发送电子邮件时,mailgun日志会说什么? – fuzzyalej 2015-04-04 08:56:03

回答

2

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

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