我想根据将从数据库中提取的应用程序用户提供不同的发件人电子邮件凭据。
答案 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_now
或deliver_later