title: Mandrill API sending scheduled emails with send_at
body: <p>The documentation isn't very clear how to use the send_at parameter. I am sending a scheduled email using the function below. I have tried different versions of the datetime required by the API documentation.</p>
  
  <p>All my emails are being send right away and not scheduled.</p>
  
  <pre><code>  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 &gt; 1) ? [{"email"=&gt;recipient,"name"=&gt;recipient_names[index], "type"=&gt;"to"}] :
              [{"email"=&gt;recipient,
                "name"=&gt;recipient_names[index],
                "type"=&gt;"to"}, 
              {"email"=&gt;current_user.email,
                "name"=&gt;current_user.name,
                "type"=&gt;"cc"}]
  
        message = { 
          :from_name=&gt; current_user.name,
          :from_email=&gt; current_user.email,
          :to=&gt; to_address,
          :subject=&gt; temp_subject, 
          :html=&gt; temp_body,
          :auto_text=&gt;true,
          :tags=&gt; ["members"],    
          :track_opens=&gt;true,
          :track_clicks=&gt;true,        
          :preserve_recipients =&gt; 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 =&gt; e
          puts "A mandrill error occurred: #{e.class} - #{e.message}" 
          next
        end
      end
    end
  </code></pre>
  
  <p><a href="https://mandrillapp.com/api/docs/messages.ruby.html#method=send" rel="nofollow">https://mandrillapp.com/api/docs/messages.ruby.html#method=send</a></p>