laravel-imap
laravel-imap copied to clipboard
Could not clean my mailbox
I just implemented a function that trying to clean mailbox.
And it always delete a few mails, not all.
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$client = new ClientManager();
$client = $client->make([
'host' => 'imap.gmail.com',
'port' => 993,
'encryption' => 'ssl',
'validate_cert' => true,
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'protocol' => 'imap'
]);
$client->connect();
$folder = $client->getFolderByName('INBOX');
foreach ($folder->messages()->all()->get() as $message) {
$message->delete();
}
}
Hi @Yooootsuba ,
you have to call $client->expunge() at the end. Otherwise those changes aren't committed on the server and therefor the messages won't get deleted. Alternative, you could call $message->delete(true) instead.
Best regards & happy coding,