Rails 4.2.1
Ruby 2.1.5
I am trying to use ActionMailer to send an email to a number of recipients, but I want the recipients to be all in the :Bcc field.
In my conttollers/communications_controller.rb, I have:
  def create
    @communication = Communication.new(communication_params)
    @message_elements = construct_message_body(communication_params)
    @communication.message = @message_elements.to_json
    @communication.originator_id = current_user.id
    users_email_groups = users_emails
    @communication.recipients = users_email_groups.to_json
    respond_to do |format|
      if @communication.save
        users_email_groups.each do |recipients|
          logger.info("Recipients - start:")
          logger.info(recipients)
          MyMailer.communication_to_all_users(subject, recipients, message_elements).deliver_later
        end
        format.html { redirect_to root_path, notice: 'Email was successfully created.' }
      else
        format.html { render :new }
      end
    end
  end
In my models/my_mailer.rb, I have:
  def communication_to_all_users(subject, recipients, message_elements)
    logger.info("Module: #{__FILE__} - Line: #{__LINE__}")
    @message_elements = message_elements
    mail(:subject => subject,
         :to => Rails.application.secrets.email_provider_username,
         :bcc => recipients)
  end
When the code is run, I get the message:
Incomplete response received from application
And in the log file, I have:
Processing by CommunicationsController#create as HTML
  Parameters: {"utf8"=>"✓", "communication"=>{"subject"=>"Test Message - 2018-04-05 04:58", "paragraph_one"=>"Para 1 test", "paragraph_two"=>"", "paragraph_three"=>"", "paragraph_four"=>"", "paragraph_five"=>"", "signature"=>""}, "commit"=>"Send Message"}
    SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1[0m
    SELECT `users`.`id`, `users`.`email` FROM `users`
    INSERT INTO `communications` (`subject`, `message`, `originator_id`, `recipients`, `created_at`, `updated_at`) VALUES ('Test Message - 2018-04-05 04:58', '[\"Para 1 test\"]', 1, '[[\"adam@xxxx.com\",\"eve@xxxx.org\"]]', '2018-04-09 00:10:34', '2018-04-09 00:10:34')
Recipients - start:
["adam@xxxx.com","eve@xxxx.org"]
Completed 500 Internal Server Error in 19ms (ActiveRecord: 3.2ms)
Based on the log file, it looks like the method communication_to_all_users is never called, and up until that point, it's all fine.
Any ideas?
