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
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)