rubyのコード(file.rb)にて
ruby
1#! /usr/bin/ruby 2# coding: utf-8 3#------------------------------------------------- 4# Ruby script to get a mail via alias of postfix. 5#------------------------------------------------- 6 7require 'mail' 8require 'csv' 9require 'time' 10 11class TextProcess 12 def initialize 13 @@from_mail = 'hoge@example.jp' 14 @@to_mail = 'hogehoge@example.com' 15 @csv = "/home/mail.csv" 16 end 17 18 def mailProcess 19 CSV.foreach(@csv) do |cs| 20 flg = 0 21 date = Time.strptime(cs[6].to_s,'%Y年%m月%d日') 22 today = Time.now 23 three_date_before = date - 259200 24 two_date_before = date - 172800 25 one_date_before = date - 86400 26 if three_date_before <= today && today < two_date_before 27 flg = 1 28 event_date = '3日前' 29 elsif one_date_before <= today && today < date 30 flg = 1 31 event_date = '前日' 32 end 33 if flg == 1 34 mail = Mail.new do 35 from @@from_mail 36 to @@to_mail 37 subject "#{event_date}のお知らせです" 38 body "氏名:#{cs[0]}\n メールアドレス:#{cs[1]}\n 会場:#{cs[2]}\n 日時:#{cs[3]}" 39 end 40 mail.charset = 'utf-8' 41 mail.delivery_method :sendmail 42 mail.deliver 43 end 44 end 45 end 46end 47 48exit unless $0 == __FILE__ 49TextProcess.new.mailProcess 50
csvファイルについて
|列1|列2|列3|列4|
|:--|:--:|--:|
|氏名|メールアドレス|会場|2018年8月3日|
以上のデータから
ruby file.rb
を起動すると、エラー表示されることなく動かなくなります…
初心者での質問で申し訳ございませんがどこが違うのかがわかりません…
ご助力のほどよろしくお願いします…
あなたの回答
tips
プレビュー