Files
eminuxCRM/app/models/mail_identity.rb
T
eminuxandCursor c4e5f289cf
CI / scan_ruby (push) Failing after 11m20s
CI / scan_js (push) Successful in 10m35s
CI / lint (push) Has been cancelled
Commit iniziale di eminuxCRM: CRM Rails con pipeline, campagne email e Docker.
Include autenticazione, progetti isolati, mail marketing HTML con SMTP, test A/B e editor WYSIWYG.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-17 23:01:48 +02:00

42 lines
1.3 KiB
Ruby

class MailIdentity < ApplicationRecord
include Auditable
encrypts :smtp_password
require "openssl"
has_many :mailings, dependent: :restrict_with_exception
ENCRYPTIONS = Catalog::MAIL_ENCRYPTIONS.keys.freeze
validates :name, :from_name, :from_email, :smtp_host, :smtp_port, presence: true
validates :from_email, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :reply_to, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true
validates :smtp_port, numericality: { in: 1..65535 }
validates :encryption, inclusion: { in: ENCRYPTIONS }
validates :smtp_authentication, inclusion: { in: Catalog::MAIL_AUTH_METHODS.keys }
scope :active, -> { where(active: true) }
scope :ordered, -> { order(:name) }
def from_header
%(#{from_name} <#{from_email}>)
end
def smtp_settings
settings = {
address: smtp_host,
port: smtp_port,
enable_starttls_auto: encryption == "starttls",
ssl: encryption == "tls",
openssl_verify_mode: verify_ssl? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
}
if smtp_username.present?
settings[:user_name] = smtp_username
settings[:password] = smtp_password
settings[:authentication] = smtp_authentication.to_sym
end
settings
end
end