10

Is there any method to read all mails (i.e. both read and unread) using Gmail API with OAuth.

The following link returns only new mails:

https://gmail.google.com/gmail/feed/atom

So I want all Emails to be retrieved.
Please help me.

informatik01
  • 16,038
  • 10
  • 74
  • 104
user1051536
  • 185
  • 2
  • 3
  • 9
  • You can edit [your existing question](http://stackoverflow.com/questions/8178695/how-do-i-download-or-read-email-attachments-from-google-gmail-api-with-oauth) instead of reposting. – BoltClock Nov 21 '11 at 18:38

3 Answers3

10

On June 25, 2014 Google released new Gmail API that can be used to easily gather messages, threads, labels and more from Gmail accounts. Service is OAuth 2 protected. They provide nice client libraries for Python, .NET and Java and wonderful documentation for those doing RESTful implementation.

I suggest using their API instead of IMAP - because Gmail has and supports many features that were not designed to run over IMAP. Features like search, tagging, etc...

You can also check their YouTube video for a nicer introduction.

cbmeeks
  • 11,248
  • 22
  • 85
  • 136
Oto Brglez
  • 4,113
  • 1
  • 26
  • 33
3

edited: IMAP example to retrieve email count. Shows the count of all my mails. Seems to work this way.

<?php

$imap = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', $username, $password);
$emails = imap_search($imap, 'ALL');

if($emails) {
        echo count($emails);
}

imap_close($inbox);
?>
sascha
  • 4,671
  • 3
  • 36
  • 54
  • Even IMAP sends only new messages – user1051536 Nov 18 '11 at 07:35
  • IMAP is for serverside control of your mails. How should email programs download every mail via IMAP, if it would only load new mails? Are you sure you did every correct? – sascha Nov 18 '11 at 07:42
  • Yeah Sn0opy i did it correctly..In fact i also created a email desktop client with IMAP to retrieve emails..But it only gets the unread ones and not all..If u have any example then could u please share with me..m all staked since last one week behind this..i really need help – user1051536 Nov 18 '11 at 07:46
  • Found these tips on Google and SO: you can use Zend_Mail_Protocol_Imap with `requestAndResponse()`. So you could use `XOAUTH` including the hash instead of `LOGIN` which is used by `imap_open()`. I think, this will be the last tip I could give you. Every other methods will be: use fsockopen() and build every request by hand. – sascha Nov 18 '11 at 11:22
3

There is sample code. Alter the code as per your needs.. https://developers.google.com/google-apps/gmail/xoauth2_libraries

Anthony Hatzopoulos
  • 10,437
  • 2
  • 40
  • 57
Jeyanth Kumar
  • 1,589
  • 3
  • 23
  • 48