Aug 31, 2023
0
Level 1
How to use Webklex with Laravel
Hi all, I need to read from a imap server only recent email, for example only from 3 days ago, but with Webklex I don't know how to obtain it. I made this controller but it returns an error of overflow memory: "message: Allowed memory size of 134217728 bytes exhausted (tried to allocate 11833520 bytes)". I think it's because messages are too many. This is my controller:
<?php
namespace App\Http\Controllers\Mailer;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Webklex\IMAP\Facades\Client;
class MailerController extends Controller
{
public function read(Request $req){
$client = Client::account('default');
//Connect to the IMAP Server
$client->connect();
//Get all Mailboxes
$folders = $client->getFolders();
$messages = [];
//Loop through every Mailbox
foreach($folders as $folder){
$messages[] = $folder->messages()->all()->get();
}
return response()->json([
'folders' => $folders,
'messages' => $messages
],200);
}
}
Is there any way to read only latest messages? Does anyone know where to find good documentation on this library? Thank you. Bye.
Please or to participate in this conversation.