Micheal
Micheal

Reputation: 2322

ruby on rails action mailer not receiving emails to arrays from a yaml file

I have an issue where i am able to send email via the mailer for a hardcoded array. But the email does not go through for an array picked up from config.yml

Here is my config.yml

company:
  email:
    - [email protected]
    - [email protected]
    - [email protected]

This is my mailer class:

class ReportMailer < ActionMailer::Base
  default :from => "[email protected]"


  def send_report(company, file)

      mail(:to=> "#{CONFIG[company]['email']}", :subject => "Daily  Report")
    end
  end
end

when run it in my rails console & view the logs, seems like everything was executed fine but I did not receive my email:

[DEBUG] 2016-04-21 18:21:29 :: Date: Thu, 21 Apr 2016 18:21:29 -0400
From: [email protected]
to: ["[email protected]", "[email protected]","[email protected]"]
 ...
 ...

 [INFO] 2016-04-21 18:21:29 ::
Sent mail to ["[email protected]", "[email protected]", "[email protected]"]

If i change my code & replace it with hardcoded array instead of reading from config.yml it works fine.

Am i reading the yaml array wrong?

Upvotes: 0

Views: 333

Answers (1)

Petr Gazarov
Petr Gazarov

Reputation: 3821

As correctly pointed out in the comment by @Alfie, you are passing a stringified array to to:.

CONFIG[company]['email'] returns an array, then string interpolation calls to_s on it and you end up with

"['[email protected]', '[email protected]','[email protected]']"

Just pass in the array without inserting it into a string:

mail(:to=> CONFIG[company]['email'], :subject => "Daily  Report")

Upvotes: 1

Related Questions