Question

What I am trying to do is I am authenticating user with my google oauth and using access type offline its returning 2 tokens 1 is access token and another is refresh token well I am workin g with google oauth so sorry maybe its a stupid question but currently I don't know is it possible to read emails with imap with using access token instead of password, my imap is working fine when using password but not with access token maybe I am missing some permission or is it not possible to read emails with access token.

Or is there any other way to read users email I want to grab user signature from his sent box but its not working if you guys requires any more information please comment.

<?php ob_start(); session_start();
$token  = json_decode($_SESSION['token']);
print_r($token);
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'themohitbumb@gmail.com';
$password = $token->refresh_token;

$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
print_r($inbox);
imap_close($inbox);
?>
Was it helpful?

Solution

Got my answer by my own : http://www.247techblog.com/read-others-email-google-xoauth-gmail-account/ with help of MAX's comment I would like to select your link as my answer but as you posted it as comment so I write a small article on it for person who will search same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top