我正在尝试使用gmail gem循环遍历电子邮件中的数组(根据我的理解,它使用邮件gem发送邮件)。
如何使用mail gem在电子邮件正文中循环播放数组?看起来很简单,然而,我无法理解它。
以下方法不起作用,但显示了我想要做的事情。
def deliver_mail(gmail, email, result, request_type)
client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => 'bigmake_development')
investments = client.query("SELECT * FROM investments WHERE investor_id = '#{result[:id]}'")
gmail.deliver do
to email.from_addrs
subject "My Subject!"
body do
investments.each do |i|
i['target']
i['deal_type']
i['round']
i['deal_date']
end
end
end
puts "Email reply sent to #{email.from_addrs}"
end
我见过的工作示例通常是这样的格式:
def deliver_mail(gmail, email, result, request_type)
gmail.deliver do
to email.from_addrs
subject "My Subject!"
body "Hello!"
# or like this
body File.load('body.txt')
end
end
但是,我认为这些方法都不会很好用。