# config/initializers/smtp.rb
# Configuração de e-mail 100% via ENV — só ativa se SMTP_USERNAME existir
if ENV['SMTP_USERNAME'].present?
  Rails.application.config.action_mailer.delivery_method = :smtp
  Rails.application.config.action_mailer.smtp_settings = {
    address:              ENV['SMTP_ADDRESS'],
    port:                 ENV.fetch('SMTP_PORT', 587).to_i,
    user_name:            ENV['SMTP_USERNAME'],
    password:             ENV['SMTP_PASSWORD'],
    domain:               ENV['SMTP_DOMAIN'],
    authentication:       'plain',
    enable_starttls_auto: true
  }
  Rails.application.config.action_mailer.default_url_options = {
    host: ENV.fetch('APP_HOST', 'localhost:3000')
  }
end
