LoginSignup
3
3

More than 5 years have passed since last update.

RubyのNet::IMAPで各種のメールを取得するための設定

Last updated at Posted at 2015-02-10

背景

管理しているメールアドレスが複数あり、それらが端末ごとに分散しているため一括管理をするためにNet::IMAPを使って処理を行うための設定方法をまとめた(ただし、自分が使っているアカウントのみ)。

Net::IMAPの簡易コード

各アカウントにログインし、メール数をカウントするスクリプト
hostname,port,ssl,username,passwordが各種アカウントに応じて変わる。

imap = Net::IMAP.new(hostname,port,ssl)
imap.login(username,password)
imap.select('INBOX')
puts imap.responses['EXISTS'].last
imap.disconnect

各アカウントの設定情報

アカウント hostname port host username 備考
さくらのレンタルサーバー サーバー名 143 false メールアドレス
icloud imap.mail.me.com 993 true ユーザー名のみ(@以降は不要)
gmail imap.gmail.com 993 true メールアドレス gmailの設定で「IMAPを有効」及び「安全性の低いアプリからのアクセスの許可」の設定が必要
softbank imap.softbank.jp 993 true ユーザー名のみ(@以降は不要) i.softbank.jpアドレスはIMAP対応(ただし、推奨されてはいない模様)

その他

  • パスワードは各自が設定したものを使用
  • softbankアカウント
    • 接続の継続時間が他のアカウントと比較して短い模様。
    • Net::IMAP#authenticateはサポートされておらず、Net::IMAP#loginでログインする必要がある。
3
3
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
3
3