Ruby Mandrill API使用发送地址发送计划电子邮件

Ruby Mandrill API使用发送地址发送计划电子邮件,ruby,email,mandrill,Ruby,Email,Mandrill,文档中不太清楚如何使用send_at参数。我正在使用下面的功能发送一封预定的电子邮件。我尝试了API文档所需的不同版本的datetime 我所有的电子邮件都会立即发送,没有预定时间 def send_member_email_batch(current_user, recipient_emails, recipient_names, subject, body, scheduled) m = Mandrill::API.new ENV["MANDRILL_APIKEY"]

文档中不太清楚如何使用send_at参数。我正在使用下面的功能发送一封预定的电子邮件。我尝试了API文档所需的不同版本的datetime

我所有的电子邮件都会立即发送,没有预定时间

  def send_member_email_batch(current_user, recipient_emails, recipient_names, subject, body, scheduled)
    m = Mandrill::API.new ENV["MANDRILL_APIKEY"]

    recipient_emails.each_with_index do |recipient, index|
      to_address = (recipient_emails.length > 1) ? [{"email"=>recipient,"name"=>recipient_names[index], "type"=>"to"}] :
            [{"email"=>recipient,
              "name"=>recipient_names[index],
              "type"=>"to"}, 
            {"email"=>current_user.email,
              "name"=>current_user.name,
              "type"=>"cc"}]

      message = { 
        :from_name=> current_user.name,
        :from_email=> current_user.email,
        :to=> to_address,
        :subject=> temp_subject, 
        :html=> temp_body,
        :auto_text=>true,
        :tags=> ["members"],    
        :track_opens=>true,
        :track_clicks=>true,        
        :preserve_recipients => false
      } 
        time_now = DateTime.now.utc
        time_now += (1 + ((5-time_now.wday) % 7))
        time_now = time_now.change({hour: 12, min: 3, sec: 0 }).strftime('%F %T')
        puts time_now #2015-10-10 12:03:00

        send_at = time_now

      #puts "to: #{recipient}, subject = #{temp_subject}, message = #{temp_body}"
      begin
        result = m.messages.send message, send_at
        puts result #email is not scheduled
      rescue Mandrill::Error => e
        puts "A mandrill error occurred: #{e.class} - #{e.message}" 
        next
      end
    end
  end

来自mandrill api文档:

当此消息应以YYYY-MM-DD HH:MM:SS格式作为UTC时间戳发送时。如果指定过去的时间,则会立即发送消息。额外费用适用于预定电子邮件,此功能仅适用于具有正余额的帐户


如果我不得不猜测,我会猜测
send\u at=time\u now
需要变成
send\u at=time\u now。要使send\u符合所需的格式。

找到了答案,如果你想使用定时电子邮件,你必须包括异步和ip池

async = false
ip_pool = "Main Pool"
send_at = "example send_at"
result = mandrill.messages.send message, async, ip_pool, send_at

使用send_at时不需要这些参数。不过,很可能您看到的是“排队”响应,因为您不是异步发送的。@Kaitlin Mandrill很有趣,您在Mandrill工作,却告诉我不是这样。需要让API工作。事实上,我在这个问题上花了好几个小时才弄明白。@Kaitlin Mandrill嗨Kaitlin,你能帮我看看这个问题吗?谢谢!!你会不会碰巧知道你可以提前多少时间和曼德里尔安排。