【问题标题】:Rails 4 - mail is not delivered if is sent to multiple recipients (using Sendgrid)Rails 4 - 如果将邮件发送给多个收件人(使用 Sendgrid),则不会传递邮件
【发布时间】:2016-03-09 05:29:28
【问题描述】:

我想每天多次向注册我的应用程序的用户发送一条包含我的产品的消息。 这是我使用的邮件方法:

  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

这是为什么呢?试图找出原因,但仍然没有成功。

【问题讨论】:

  • 除非email.blank,否则代码有什么用?试着删除它。

标签: ruby-on-rails ruby actionmailer sendgrid


【解决方案1】:

试试这样:

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

【讨论】:

    猜你喜欢
    • 2012-01-12
    • 1970-01-01
    • 2012-10-23
    • 2017-09-26
    • 2014-02-06
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多