Pergunta

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

Foi útil?

Solução

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

Outras dicas

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!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top