Add IP-based SMTP authentication (#1149)

This commit is contained in:
Charlie Smurthwaite
2020-07-17 11:43:51 +01:00
committed by GitHub
parent 5c7802d218
commit 9a3d568b27
9 changed files with 103 additions and 14 deletions
+12 -2
View File
@@ -312,8 +312,18 @@ module Postal
end
else
# This is unaccepted mail
'530 Authentication required'
# User is trying to relay but is not authenticated. Try to authenticate by IP address
@credential = Credential.where(:type => 'SMTP-IP').all.sort_by { |c| c.ipaddr&.prefix || 0 }.reverse.find do |credential|
credential.ipaddr.include?(@ip_address)
end
if @credential
# Retry with credential
@credential.use
rcpt_to(data)
else
'530 Authentication required'
end
end
end