簡體   English   中英

創建自定義郵件時如何使用Rails郵件程序設置?

[英]How to use Rails mailer settings when creating a custom Mail?

我正在Rails應用程序中創建一個Mail對象,並希望它選擇郵件程序設置:

original = UserMailer.new_registration
original.deliver# Does the job

custom = Mail.new(original.to_s)
custom.deliver # Fails: OpenSSL::SSL::SSLError: hostname does not match the server certificate

顯然,自定義Mail對象沒有采用Rails設置。

查看代碼 ,我們可以通過以下方式從郵件程序中獲取配置:

custom = ::Mail.new(raw_email)
key = Rails.application.config.action_mailer.delivery_method
delivery_method = ActionMailer::Base.delivery_methods.fetch(key)
delivery_settings = ActionMailer::Base.send("#{key}_settings")
custom.delivery_method(delivery_method, delivery_settings)
custom.deliver

要使用Rails發送自定義郵件,請閱讀此內容。

http://mdushyanth.wordpress.com/2011/08/06/custom-mail-delivery-method-in-rails-3/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM