開発環境:ubuntu 18.0.4
したいこと
fetchmailを用いてメールを取ってき,textProcessing.rbにメールの内容を入れ特定の処理を行い,csvファイルにFROM,氏名,参加イベント日時(氏名,参加イベント日時については本文に書いています)を取ってきたく思います。
fetchmailの設定内容について
defaults uidl no mimedecode no rewrite mda /home/name/process/textProcessing.rb # メールを渡すプログラムのフル>パス keep poll mail.example.jp protocol POP3 username example@example.jp password xxxxxxxx ssl
textProcessing.rbについて
ruby
1#! /usr/bin/ruby 2# coding: utf-8 3#------------------------------------------------- 4# Ruby script to get a mail via alias of postfix. 5#------------------------------------------------- 6require 'mail' 7 8class GetMail 9 def initialize 10 dt = Time.now.strftime("%Y%m%d_%H%M%S%L") 11 @out_file = "/home/name/#{dt}.txt" 12 end 13 14 def execute 15 open(@out_file, "w") do |f| 16 mails = Mail.new($stdin.read) 17 for mail in mails 18 f.puts mail.from.first 19 f.puts mail.subject 20 f.puts "Body:\n#{mail.body.decoded.encode("UTF-8", mail.charset)}" 21 end 22 end 23 rescue => e 24 $stderr.puts "[#{e.class}] #{e.message}" 25 e.backtrace.each{|trace| $stderr.puts "\t#{trace}"} 26 exit 1 27 end 28end 29 30exit unless $0 == __FILE__ 31GetMail.new.execute
以下エラーが出てきます。
[NoMethodError] undefined method `each' for nil:NilClass
わからない点について
・一度fetchmailを回すともう一回メール内容が取れなくなるのでその対処
・複数のメールアドレスの取得
・body内から特定の情報を取ってくる方法
ご助力のほどよろしくお願いします。。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/30 06:52
2018/07/30 07:21
2018/07/30 07:29
2018/07/31 00:52
2018/07/31 00:55
2018/07/31 00:58