How to get the number of unread gmail mails [closed]

痞子三分冷 提交于 2019-12-25 01:45:10

问题


Can someone help me with a code to get the numbers of unread gmail emails to php?


回答1:


Connect to gmail via IMAP protocol using functions from the IMAP module http://php.net/manual/en/book.imap.php

$mbox = imap_open("{imap.example.org:143}INBOX", "username", "password")
     or die("can't connect: " . imap_last_error());

$MC = imap_check($mbox);

// Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
$seen = 0;
$unseen = 0;
foreach ($result as $overview) {
    if($overview->seen){
      $counter++;
    } else {
      $unseen++;
    }
}
imap_close($mbox);

echo "Seen $seen, unseen $unseen"



回答2:


You could use some this API to get your inbox feed : http://code.google.com/apis/gmail/docs/inbox_feed.html

But there is plenty of libraries to access these feed in PHp I guess.



来源:https://stackoverflow.com/questions/8467965/how-to-get-the-number-of-unread-gmail-mails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!