Action Mailer无法执行方法

时间:2018-04-09 00:27:48

标签: ruby-on-rails actionmailer

Rails 4.2.1
Ruby 2.1.5

我正在尝试使用ActionMailer向多个收件人发送电子邮件,但我希望收件人全部位于:密件抄送字段。

在我的conttollers / communications_controller.rb中,我有:

  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

在我的models / my_mailer.rb中,我有:

  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

当代码运行时,我收到消息:

Incomplete response received from application

在日志文件中,我有:

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)

基于日志文件,看起来似乎从不调用communication_to_all_users方法,直到那时为止,它都很好。

有什么想法吗?

0 个答案:

没有答案