LoginSignup
4
4

More than 5 years have passed since last update.

Rubyのimapでyahooメール受信

Posted at

すこしはまったのでメモ

Yahooメールのサーバー設定
受信メール(IMAP)サーバー imap.mail.yahoo.co.jp
受信メール(IMAP)通信方法 SSL
受信メール(IMAP)ポート番号 993
require 'net/imap'
require 'io/console'

$stderr.print 'user : '; user = gets.chomp
$stderr.print 'pass : '; pass = STDIN.noecho(&:gets).chomp

imap = Net::IMAP.new('imap.mail.yahoo.co.jp', 993, true, 'cacert.pem')

imap.authenticate('LOGIN', user, pass)
imap.examine('INBOX')

msgids = imap.search(["ALL"]).last #最新一件を取得
imap.fetch(msgids, %w(BODY[HEADER] BODY[TEXT])).each do |mail|
    puts mail.attr["BODY[HEADER]"]
    puts mail.attr["BODY[TEXT]"]
end

cacert.pemという証明書が必要。自分は http://curl.haxx.se/ca/cacert.pem から持ってきた。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4