class UserMailer < ActionMailer::Base
  default from: 'nixers@fixrnix.in'

  def welcome_email(user)
    @user = user
    @url  = 'http://www.fixrnix.in'
    mail(to: @user.email , subject: 'Welcome to FixNix Audit Management')
  end
end

How can i send email to all users instead of single user mail(to: @user.email , subject: 'Welcome to FixNix Audit Management')

有帮助吗?

解决方案

You can pass array of addresses as well:

def welcome_email(users)
  @url  = 'http://www.fixrnix.in'
  mail(to: users.pluck[:email] , subject: 'Welcome to FixNix Audit Management')
end

However, if your email body depends on the user or you don't want mailed users to see other users's addresses you can't do this. You need to create a new message for each user and send it separately.

users.each do |user|
  YourMailer.welcome_email(user).deliver
end

其他提示

You can simply do this in your mailer

emails = users.collect(&:email).join(", ")
mail(to: emails, subject: 'Welcome to FixNix Audit Management')

Hope this helps!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top