我很难找到一个解决方案(差不多3天)我在incoming_controller.rb中的代码似乎是正确的,我在rails控制台测试它并且看来唯一的问题是当我发送电子邮件时(来自我的gmail)我的mailgun电子邮件,我声明的路线将不会与我的rails应用程序连接,我的邮件日志中会收到警告 .
我要做的是允许用户发送电子邮件并将正文内容转换为书签,并将其保存在数据库中,并将电子邮件的主题作为主题 .
这是我的 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
Note: mailgun适用于从Devise向用户发送电子邮件确认指令,因此配置正确,我不能做的是使mailgun接收电子邮件并通过incoming_controller参数将它们存储在我的rails db中 .
我究竟做错了什么?
我的邮件路线如下:
Filter Expression: catch_all()
Actions: forward(“http://bookmark-this.herokuapp.com/incoming/”)
这是我发送电子邮件时在mailgun中收到的警告日志:
这是github上的项目存储库:https://github.com/bntzio/bookmark-this
非常感谢!
1 回答
Mailgun正在接收
301
状态代码,被重定向到https
endpoints 而不是普通 endpoints . 您似乎已激活SSL但未更新mailgun配置上的完整路由以使用它 . 您应该将其更新为: