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

后端 未结 6 1512
不知归路
不知归路 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:37

    Since Rails 4+ it works to give the credentials directly via the delivery_method_options parameter:

    class UserMailer < ApplicationMailer
      def welcome_email
        @user = params[:user]
        @url  = user_url(@user)
        delivery_options = { user_name: params[:company].smtp_user,
                             password: params[:company].smtp_password,
                             address: params[:company].smtp_host }
        mail(to: @user.email,
             subject: "Please see the Terms and Conditions attached",
             delivery_method_options: delivery_options)
      end
    end
    

    See Sending Emails with Dynamic Delivery Options (Rails Guides)

提交回复
热议问题