-1

I want to access my gmail inbox list in laravel php using Gmail API.I can do it on the console using PHP but it is difficult to find the sources to run the code on website using Laravel Framework.

Note that I don't want to send the email to the recipient but wanted to fetch my whole inbox list of emails on my website. Had anyone face this issue and got any result?

Kevin
  • 13
  • 1
  • 4
  • Please see: https://stackoverflow.com/questions/32515245/how-to-to-send-mail-using-gmail-in-laravel – Alexander Dobernig Jan 21 '21 at 08:26
  • 1
    Does this answer your question? [How to to send mail using gmail in Laravel?](https://stackoverflow.com/questions/32515245/how-to-to-send-mail-using-gmail-in-laravel) – Alexander Dobernig Jan 21 '21 at 08:27
  • Hi ! What have you tried so far? Why is the [PHP quickstart guide](https://developers.google.com/gmail/api/quickstart/php) not suitable for your case scenario? – Mateo Randwolf Jan 21 '21 at 09:35
  • The PHP quickstart guide is for Console application to read the labels of the gmail application whereas I want to fetch my whole inbox (not to send the email) list on the website(not on the console). – Kevin Jan 21 '21 at 12:03
  • Welcome to StackOverflow! Have you tried anything so far? StackOverflow isn't a free code-writing service and you are expected to do your research and try to solve your own problem first. You'll get a better response if you show that you've made some effort, eg show us what you've tried, why you tried that, describe what happens, etc. For tips on formulating your question read [how to ask](https://stackoverflow.com/questions/how-to-ask), and how to create a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve). Googling "Laravel GMail client" turns up plenty of hits? – Don't Panic Jan 25 '21 at 08:20

1 Answers1

1

If you want to retrieve your email inbox to then use these messages in your website you can combine the method users.messages.list() which will return a list of your email messages ids as described in the documentation along with users.messages.get() which will return the message itself.

In PHP these methods would be listUserMessages and get returning each a ListMessagesResponse and a GmailMessage. With them you can store the content of each message as an element of an array to then use this array in your website in your preferred way.

The following piece of code assumes that you have authorised your application correctly and only focuses on the logic to get an array of your inbox in PHP, it also has self explanatory comments:

// Run the method list which will return the list of messages 
$list = $gmail->users_messages->listUsersMessages('me');

// Get the actual list 
$messageList = $list->getMessages();

// Create array where we will store our messages
$messages = array();

// iterate over all the elements retrieved by the method list
foreach($messageList as $msg){

  // GET individual message
  $message = $gmail->users_messages->get('me',$msg->id);
  
  // Push the element into our array of messages
  array_push($messages,)
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Mateo Randwolf
  • 2,823
  • 1
  • 6
  • 17
  • Please try to refrain from adding a "Solution" to all your solutions. All answers contain solutions, so it is redundant - that a solution is being offered is expected `:=)`. – halfer Jan 26 '21 at 20:32