如何根据rails中的应用程序用户更改发件人电子邮件凭据

时间:2018-04-24 11:22:34

标签: ruby-on-rails ruby-on-rails-3

我想根据将从数据库中提取的应用程序用户提供不同的发件人电子邮件凭据。

1 个答案:

答案 0 :(得分:0)

如果您正在使用ActionMailer,则可以设置':

fetch_sender = Object.select(:email, :name).find(id)
mail(from: "#{fetch_sender.name} <#{fetch_sender.email}>", to: 'Receiver <example@receiver.com>', subject: 'Something')

ActionMailer类的示例:

应用程序/邮寄者/ custom_mailer.rb

class CustomMailer < ApplicationMailer
  def custom(sender, receiver)
    mail(from: "#{sender.name} <#{sender.email}>", to: "#{receiver.name} <#{receiver.email}>", subject: 'Something')
  end
end

发送

CustomMailer.custom(sender, receiver).deliver

P.s。如果你有sidekiq或其他东西,你可以使用deliver_nowdeliver_later