Added an API to ask if an incoming email should be dropped at the SMTP level.
This lets an SMTP server optionally decide if it should reject a mail without passing it on to Discourse at all, possibly before even reading the email's payload, to prevent spam-induced backscatter and save resources. This just does the bare minimum sanity checking that could prevent obvious backscatter. For legit errors from legit users, Discourse will still send a much more pleasant reply email.
This commit is contained in:
parent
3eb125c39b
commit
e15d11df18
|
@ -69,6 +69,19 @@ class Admin::EmailController < Admin::AdminController
|
|||
end
|
||||
end
|
||||
|
||||
def smtp_should_reject
|
||||
params.require(:from)
|
||||
params.require(:to)
|
||||
# These strings aren't localized; they are sent to an anonymous SMTP user.
|
||||
if User.find_by_email(params[:from]).nil? && !SiteSetting.enable_staged_users
|
||||
render json: { reject: true, reason: "Mail from your address is not accepted. Do you have an account here?" }
|
||||
elsif Email::Receiver.new(params[:from]).check_address(params[:to]).nil?
|
||||
render json: { reject: true, reason: "Mail to this address is not accepted. Check the address and try to send again?" }
|
||||
else
|
||||
render json: { reject: false }
|
||||
end
|
||||
end
|
||||
|
||||
def handle_mail
|
||||
params.require(:email)
|
||||
Email::Processor.process!(params[:email])
|
||||
|
|
|
@ -155,6 +155,7 @@ Discourse::Application.routes.draw do
|
|||
get "/incoming_from_bounced/:id" => "email#incoming_from_bounced"
|
||||
get "preview-digest" => "email#preview_digest"
|
||||
get "send-digest" => "email#send_digest"
|
||||
get "smtp_should_reject"
|
||||
post "handle_mail"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue