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
Topic 属于 User,有很多书签,User 有很多主题,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 可以很好地从 Devise 向用户发送电子邮件确认指令,因此配置正确,我不能做的是让 mailgun 接收电子邮件并使用 incoming_controller.
通过参数将它们存储在我的 rails 数据库中
我做错了什么?
我的mailgun路由如下:
过滤表达式: catch_all()
操作:转发(“http://bookmark-this.herokuapp.com/incoming/”)
这是我在发送电子邮件时在 mailgun 中收到的警告日志:
这是 github 上的项目存储库:https://github.com/bntzio/bookmark-this
非常感谢!
Mailgun 正在接收 301
状态代码,被重定向到 https
端点而不是普通端点。您似乎已经激活了 SSL,但没有更新 mailgun 配置上的完整路由以使用它。您应该将其更新为:
Actions: forward("https://bookmark-this.herokuapp.com/incoming/")
我很难找到解决方案(将近 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 有很多主题,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 可以很好地从 Devise 向用户发送电子邮件确认指令,因此配置正确,我不能做的是让 mailgun 接收电子邮件并使用 incoming_controller.
通过参数将它们存储在我的 rails 数据库中我做错了什么?
我的mailgun路由如下:
过滤表达式: catch_all()
操作:转发(“http://bookmark-this.herokuapp.com/incoming/”)
这是我在发送电子邮件时在 mailgun 中收到的警告日志:
这是 github 上的项目存储库:https://github.com/bntzio/bookmark-this
非常感谢!
Mailgun 正在接收 301
状态代码,被重定向到 https
端点而不是普通端点。您似乎已经激活了 SSL,但没有更新 mailgun 配置上的完整路由以使用它。您应该将其更新为:
Actions: forward("https://bookmark-this.herokuapp.com/incoming/")