带有 mailgun 和 rails 的电子邮件未发送给所有用户
e-mail with mailgun and rails not sent to all users
每次博客 post 被 post 编辑时,我都会尝试向所有用户发送一封电子邮件。 Mailgun 似乎可以发送电子邮件,但总是只发送给一个用户。我在生产中 运行。
我在邮件中的代码是这样的
def new_record_notification(users)
@users = User.all
@users.each do |user|
mail to: user.email, subject: "Success! You did it."
end
end
end
pins_controller.rb
# POST /pins
# POST /pins.json
def create
@pin = current_admin.pins.new(pin_params)
respond_to do |format|
if @pin.save
ModelMailer.new_record_notification(@record).deliver
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
end
end
end
我想这会解决您的问题。
mailer.rb
def new_record_notification(user)
mail to: user.email, subject: "Success! You did it."
end
pins_controller.rb
def create
@pin = current_admin.pins.new(pin_params)
respond_to do |format|
if @pin.save
@users = User.all
@users.each do |user|
ModelMailer.new_record_notification(user).deliver
end
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
end
end
end
或
您可以尝试关注。
mailer.rb
def new_record_notification(users)
recipients = User.all.collect{ |user| user.email }
mail to: recipients, subject: "Success! You did it."
end
pins_controller.rb
def create
@pin = current_admin.pins.new(pin_params)
respond_to do |format|
if @pin.save
ModelMailer.new_record_notification(@record).deliver
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
end
end
end
每次博客 post 被 post 编辑时,我都会尝试向所有用户发送一封电子邮件。 Mailgun 似乎可以发送电子邮件,但总是只发送给一个用户。我在生产中 运行。
我在邮件中的代码是这样的
def new_record_notification(users)
@users = User.all
@users.each do |user|
mail to: user.email, subject: "Success! You did it."
end
end
end
pins_controller.rb
# POST /pins
# POST /pins.json
def create
@pin = current_admin.pins.new(pin_params)
respond_to do |format|
if @pin.save
ModelMailer.new_record_notification(@record).deliver
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
end
end
end
我想这会解决您的问题。
mailer.rb
def new_record_notification(user)
mail to: user.email, subject: "Success! You did it."
end
pins_controller.rb
def create
@pin = current_admin.pins.new(pin_params)
respond_to do |format|
if @pin.save
@users = User.all
@users.each do |user|
ModelMailer.new_record_notification(user).deliver
end
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
end
end
end
或
您可以尝试关注。
mailer.rb
def new_record_notification(users)
recipients = User.all.collect{ |user| user.email }
mail to: recipients, subject: "Success! You did it."
end
pins_controller.rb
def create
@pin = current_admin.pins.new(pin_params)
respond_to do |format|
if @pin.save
ModelMailer.new_record_notification(@record).deliver
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
end
end
end