문제

    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