array = ["abc","mohasdan","321","324324"]
recipients = ["xxx@example.com"]
recipients_formatted = []
recipients.each {|s| recipients_formatted << "To: #{s}"}
message = <<MESSAGE_END
From: xxx@example.com <xxx@example.com>
#{recipients_formatted}
MIME-Version: 1.0
Content-type: text/html
Subject: Chef Report
<html>
<head>
<style type="text/css">
table {border-collapse:collapse;}
table, td, th {border:1px solid black;padding:5px;}
</style>
</head>
<body>
<h2>Chef Check-in Report</h2>
<p>
<p>
<table border=1>
<tr>
<th>Node</th>
<th>Time Since Last Check-in (Mins)</th>
</tr>
</table>
</body>
</html>
MESSAGE_END
Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, 'xxx@example.com',
recipients
end
上記のコードは、次のようなテーブルを含む電子メールを送信します。
Chef (column1) | Check-in Report(column2) (row 1)
配列の内容を、電子メールで送信されるテーブルに配置します。行1の最初の列の最初の配列要素、行1の2番目の列の2番目の配列要素が必要です。行2の最初の列の3番目の配列要素、行2の2番目の列の4番目の配列要素というように続きます。