2016-04-21 89 views
0

我有一个问题,我可以通过邮件发送电子邮件的硬编码数组。 但电子邮件的数组不经过从config.yml轨道上的红宝石动作邮件不接收来自yaml文件的数组的电子邮件

拿起这是我config.yml

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

这是我的邮件类:

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


    def send_report(company, file) 

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

时运行在我的导轨控制台&查看日志,似乎一切都很好,但我没有收到我的电子邮件:

[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]"] 

如果我更改我的代码&将其替换为硬编码数组而不是从config.yml读取,它可以正常工作。

我读的yaml数组错了吗?

+1

你传递一个字符串转换为'to',而不是数组 – Alfie

回答

1

正如@Alfie在评论中正确指出的那样,您正在将字符串数组传递给to:

CONFIG[company]['email']返回一个数组,然后串插调用它to_s和你结束了

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

就在数组中传递,而不将其插入一个字符串:

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