How to get an unread Gmail account

I use the following code to count the number of unread messages in Gmail. However, it returns an error:

can't connect: Too many login failures 

Is there anything I don't see here?

(IMAP and POP are included in the Gmail account I'm testing.)


NOTE. It seems to work (at least for most queries). However, it takes too long - maybe 2 - 3 minutes to return with the number. Is there any way to speed it up?


Thanks!

 <?php $mbox = imap_open ("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", "username", "password", OP_READONLY) or die("can't connect: " . imap_last_error()); $check = imap_mailboxmsginfo($mbox); if ($check) { print $check->Unread; //. "/" . $check->Nmsgs; } else { print "Failed"; } ?> 
+3
source share
4 answers

You can also use Gmail Inbox Feed to get an unread account. Just send an authenticated GET request to https://mail.google.com/mail/feed/atom and check the value of the fullcount element.

+3
source

Try to display all errors that may occur:

 $mbox = imap_open("{imap.gmail.com:993/imap/ssl/novalidate-cert/norsh}Inbox", "username", "password", OP_READONLY) or die('Cannot connect to Gmail: ' . print_r(imap_errors())); 
0
source

I have the same problem and it is very simple.

Log in to your account, which you use to connect imap and at the top of the page. Google will change you with respect to accessing multiple addresses of your account, so Goolge privateent terminates this process and allows you to use your accout

and your problem will be solved.

0
source

The easiest way is to make an authenticated GET request for gmail api. url :: https://www.googleapis.com/gmail/v1/users/me/labels/UNREAD

It will return json with the number of unread messages of n threads. countUnread = response ["messagesTotal"]. For more information, see Oauth 2 playground. https://developers.google.com/oauthplayground/?code=4/-49VJwh28-eJG7xiK3UoFBchIQrCYRllnOt1TY-w0h4#

0
source

Source: https://habr.com/ru/post/1385735/


All Articles