From b123973654734c5e84f8a68618e7cab8e0cc40d6 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Sun, 17 Jul 2022 10:25:22 +0200 Subject: [PATCH] do not require an email in smtp_should_reject handler It is perfectly OK for an SMTP session not to have a FROM address [1], and while such mail will probably still be rejected/filtered at a later point by Discourse, we should not reject it at SMTP time. Currently, such mails get rejected with: 450 4.7.1 : Recipient address rejected: Internal error, API request failed [1] https://datatracker.ietf.org/doc/html/rfc5321#section-4.5.5 --- app/controllers/admin/email_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 8d54a2b4e4..251f107fe2 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -130,10 +130,9 @@ class Admin::EmailController < Admin::AdminController 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.with_email(Email.downcase(params[:from])).exists? && !SiteSetting.enable_staged_users + if params[:from].present? && !User.with_email(Email.downcase(params[:from])).exists? && !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.check_address(Email.downcase(params[:to])).nil? render json: { reject: true, reason: "Mail to this address is not accepted. Check the address and try to send again?" }