How to send emails with multiple, dynamic smtp using Actionmailer/Ruby on Rails

后端 未结 6 1508
不知归路
不知归路 2020-12-04 18:40

I saw this post but mine is slightly different:

Rails ActionMailer with multiple SMTP servers

I am allowing the users to send mail using their own SMTP crede

6条回答
  •  情歌与酒
    2020-12-04 19:35

    Here is a solution that I came up with based on the previous answers and comments. This uses an ActionMailer interceptor class.

    class UserMailer < ActionMailer::Base
      default from: proc{ @user.mail_settings[:from_address] }      
    
      class DynamicSettingsInterceptor
         def self.delivering_email(message)
           message.delivery_method.settings.merge!(@user.mail_settings)
         end
       end
       register_interceptor DynamicSettingsInterceptor
    end
    

提交回复
热议问题