Impedisce combinazioni SMTP errate tra porta e crittografia.
Evita l'errore SSL wrong version number quando SSL/TLS è impostato sulla porta 587 invece che sulla 465. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -15,6 +15,7 @@ class MailIdentity < ApplicationRecord
|
||||
validates :smtp_port, numericality: { in: 1..65535 }
|
||||
validates :encryption, inclusion: { in: ENCRYPTIONS }
|
||||
validates :smtp_authentication, inclusion: { in: Catalog::MAIL_AUTH_METHODS.keys }
|
||||
validate :encryption_matches_port
|
||||
|
||||
scope :active, -> { where(active: true) }
|
||||
scope :ordered, -> { order(:name) }
|
||||
@@ -38,4 +39,16 @@ class MailIdentity < ApplicationRecord
|
||||
end
|
||||
settings
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def encryption_matches_port
|
||||
return if smtp_port.blank? || encryption.blank?
|
||||
|
||||
if encryption == "tls" && smtp_port == 587
|
||||
errors.add(:smtp_port, "con SSL/TLS va usata la porta 465 (es. smtps.aruba.it)")
|
||||
elsif encryption == "starttls" && smtp_port == 465
|
||||
errors.add(:smtp_port, "con STARTTLS va usata la porta 587 (es. smtp.aruba.it)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user