ActionMailer의 SMTP 설정을 런타임에 구성 할 수 있도록 설정하려고하지만 발생하면 제 3 자 서비스에 연결하지 않는 것 같습니다. 메일. 다음은 메일이 보내고 전달하는 첫 번째 시나리오와 두 번째 시나리오에서 발생하는 두 가지 시나리오입니다.SMTP 설정이 동적으로 구성된 경우 ActionMailer가 메일을 배달하지 않습니다.
# config/environments/development.rb
config.action_mailer.default_url_options = { host: 'www.mysite.com' }
config.action_mailer.smtp_settings = {
:address => "smtp.thirdpartyservice.com",
:port => 587,
:domain => 'mysite.com',
:user_name => "[email protected]",
:password => "my-password",
:authentication => "plain",
:enable_starttls_auto => true
}
이 메일을 배달뿐만 아니라 미행 때 나는
이 구성을 테스트하기위한 개발 환경을 사용하고있어 두 시나리오
# config/environments/development.rb
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.delivery_method = :smtp
이 작품에 공통적 인 로그에 요청이 약간 지연되어 요청이 제 3 자 서비스로 전송되고 있음을 알 수 있습니다.
이 작동하지 않습니다
이 내가 원하는 설정이다, 내가 사용하고 사용자 정의 메일러를 사용.
class MyCustomMailer < Devise::Mailer
before_filter :use_smtp_settings
def example_mailer(record)
Rails.logger.warn self.smtp_settings
@resource = record
mail(to: record.email,
from: AppSettings.first.mailer_sender,
subject: "Example")
end
private
def use_smtp_settings
self.default_url_options[:host] = AppSettings.first.domain_address
self.smtp_settings = {
:address => AppSettings.first.smtp_address,
:port => AppSettings.first.smtp_port,
:domain => AppSettings.first.smtp_domain,
:user_name => AppSettings.first.smtp_username,
:password => AppSettings.first.smtp_password,
:authentication => "plain",
:enable_starttls_auto => true
}
end
end
#example_mailer()
방법에 레일 로거는 app_settings
테이블에서로드이라도, 제 실시 예에서 사용되는 동일한 특성을 나타낸다. 그러나 이번에는 로그를 테일링 할 때 지연이 없으므로 ActionMailer는 제 3 자 서비스에 요청을 시도하는 것조차 보이지 않습니다.
실제로! 'mail()'옵션에 오타가 있다는 것에주의하십시오. 그것은'delivery_method_settings' 대신에'delivery_method_options'이어야합니다. – Simpleton
고마워요! – pixeltrix
모든 전달 메소드에 * _settings 메소드가 있다는 사실은 나에게 delivery_method_settings :-)가되어야 함을 의미하지만 – pixeltrix