2017-08-16 92 views
1

我想通過SMTP使用通過某種Web表單提供的憑據從電子郵件發送電子郵件。因此,不是使用像這樣在啓動時配置郵件:使用自定義SMTP設置發送電子郵件

ActionMailer::Base.smtp_settings = { 
    :address    => address, 
    :domain    => domain, 
    :user_name   => user_name, 
    :password    => password, 
} 

,然後發送使用UserMailer.send_mail(user).deliver_now

我想基於獲得的變量設置SMTP設置只對一個郵件的郵件來自數據庫。

是否有可能用rails來實現這種行爲?

回答

0
class UserMailer < ApplicationMailer 
    self.smtp_settings = { 
    :address => ‘smtp.gmail.com’, :port => 587, 
    :domain => ‘gmail.com’, 
    :authentication => ‘plain’, 
    :user_name => <email_username>, 
    :password => <email_password>, 
    :enable_starttls_auto => true 
    } 

send_mail(option, data) 

    email.delivery_method.settings.merge!({:address => 
    Email.email_address, :port => Email.email_port, :domain => 
    Email.email_domain, :user_name =>Email.email_username, :password => Email.email_password, :enable_starttls_auto => true}) 
    email.deliver_now 
end 

end 

嘗試類似