Skip to content

Idle callback not fired when sending an email #568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Egensolve opened this issue Mar 23, 2025 · 0 comments
Open

Idle callback not fired when sending an email #568

Egensolve opened this issue Mar 23, 2025 · 0 comments
Labels
bug Something isn't working More information required Further information is requested validating

Comments

@Egensolve
Copy link

Describe the bug
Idle connection is established successfully with a callback for the new email, but when sending an email to that connected email from another email and being successfully added to the INBOX folder but callback was not fired.

Code to Reproduce

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Webklex\PHPIMAP\ClientManager;
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
use Webklex\PHPIMAP\Exceptions\FolderFetchingException;
use Webklex\PHPIMAP\Message;

class ImapIdleTest extends Command
{
    protected $signature = 'imap:test-idle';
    protected $description = 'Test raw IMAP IDLE using Webklex/php-imap directly';

    public function handle()
    {
        $this->info("🔄 Connecting to Gmail via IMAP...");

        $clientManager = new ClientManager();

        $client = $clientManager->make([
            'host' => 'imap.gmail.com',
            'port' => 993,
            'encryption' => 'ssl', // or 'tls' if using 587
            'validate_cert' => true,
            'username' => '[email protected]',
            'password' => 'App password', // App Password, not Gmail password
            'protocol' => 'imap'
        ]);

        try {
            $client->connect();
            $this->info("✅ Connected.");
        } catch (ConnectionFailedException $e) {
            $this->error("❌ Connection failed: " . $e->getMessage());
            return 1;
        }

        try {
            $folder = $client->getFolder('INBOX');
        } catch (FolderFetchingException $e) {
            $this->error("❌ Folder error: " . $e->getMessage());
            return 1;
        }

        $this->info("📨 Listening for new messages via IDLE...");

        try {
            $folder->idle(function (Message $message) {
                echo "\n📥 New message: " . $message->getSubject() . "\n";
            });
        } catch (ConnectionFailedException $e) {
            $this->error("❌ IDLE failed: " . $e->getMessage());
        }
    }
}

Expected behavior
What is expected is when a new email is received in the INBOX, it would echo in the terminal "📥 New message: " with the subject of the new email.

Desktop / Server:

  • OS: MacOS 15.3.1 (24D70)
  • PHP: 8.3.16
  • Gmail

Additional context
I also tried idling manually to the gmail imap servers using openssl s_client -connect imap.gmail.com:993 -crlf. After that, I logged in using a LOGIN [email protected] "my app password" which would give you success message. using a SELECT INBOX to select inbox and then a IDLE to open an idle connection. When sending a new email, it would print a number that I guess is the number of unread emails.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working More information required Further information is requested validating
Projects
None yet
Development

No branches or pull requests

2 participants