Answer the question
In order to leave comments, you need to log in
Bulk Send Emails Rails. Why is the email sent only to the last user from User.all?
def alarm_email() # TODO в будущем обрабатывать через пакеты (User.find_each)
delivery_options = {
address: "smtp.mail.ru",
port: 465,
domain: "mail.ru",
authentication: :login,
tls: true,
user_name: "[email protected]",
password: "password",
enable_starttls_auto: true
}
for user in User.all
#puts user.email
mail(to: user.email,
subject: "Subject",
delivery_method_options: delivery_options
)
#sleep (Random.new.rand(3.0..8.0))
end
end
Answer the question
In order to leave comments, you need to log in
# controller
User.all.pluck(:email).each do |email|
NoticeMailer.alarm_email(email).deliver
end
# NoticeMailer
def alarm_email(email)
# Эти настройки в конфиг нужно вынести
delivery_options = {
address: "smtp.mail.ru",
port: 465,
domain: "mail.ru",
authentication: :login,
tls: true,
user_name: "[email protected]",
password: "password",
enable_starttls_auto: true
}
mail to: email, subject: "Subject", delivery_method_options: delivery_options
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question