我想向我的用户发送一条消息,每天几次向我的应用程序注册。 这是我用于此的邮件程序方法:
def notify_users(product)
@product
emails = Customer.signed_up.pluck(:email_address)
puts "EMAILS:"
puts emails.inspect # I see here, say, 5 email addresses
emails.each do |email|
unless email.blank?
puts "Sending to #{email}" # email is displayed here properly
mail(to: email, subject: "New products", from: 'no-reply@website.com')
end
end
我发现如果emails
只包含1个电子邮件地址,则电子邮件会在电子邮件地址中发送。但是,当我确实在多个电子邮件地址上发送电子邮件时,通常只会传递最后一条消息(因此如果emails
继续["a@gmail.com", "b@gmail.com", "c@gmail.com"]
),则电子邮件仅在c@gmail.com
上发送。
为什么?试图找出原因,但仍然不成功。
答案 0 :(得分:0)
试试这样:
def send_notification_to_user(email)
puts "Sending to #{email}" # email is displayed here properly
mail(to: email, subject: "New products", from:'no-reply@website.com')
end
def notify_users(product)
@product
emails = Customer.signed_up.pluck(:email_address)
puts "EMAILS:"
puts emails.inspect # I see here, say, 5 email addresses
emails.each do |email|
unless email.blank?
send_notification_to_user(email).deliver_now
end
end
end