问题
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