oAuth


In order to use oAuth you need to obtain an access token first. Once you have the token, please proceed by setting the authentication to oauth and provide the access token as password:

/** @var \Webklex\PHPIMAP\ClientManager $cm */

$client = $cm->make([
   'host'           => 'some.host.tld',
   'port'           => 993,
   'encryption'     => 'ssl',
   'validate_cert'  => true,
   'protocol'       => 'imap',
   'username'       => 'username@host.tld',
   'password'       => 'ACCESS-TOKEN',
   'authentication' => "oauth",
]);

Google / Gmail

Connect using an application password

  1. Go to https://myaccount.google.com/ and click on "Security"
  2. Under "Signing in to Google" click on "App passwords"
  3. Click on "Select app" and choose "Mail" and click on "Select device" and choose "Other"
  4. Click on "Generate" and use the displayed password (without any spaces) as your password
/** @var \Webklex\PHPIMAP\ClientManager $cm */

$client = $cm->make([
   'host'          => 'imap.googlemail.com',
   'port'          => 993,
   'encryption'    => 'ssl',
   'validate_cert' => true,
   'protocol'      => 'imap',
   'username'      => 'username@gmail.com',
   'password'      => 'new-generated-password'
]);

Credits: @stacyprowell

Outlook / Office 365

  1. Register an app in Azure AD
  2. Configured it properly in Azure AD (add all required scopes for IMAP/SMTP like IMAP.AccessAsUser.All, offline_access, etc.)

Ensure your scope is set to https://outlook.office.com/IMAP.AccessAsUser.All

/** @var \Webklex\PHPIMAP\ClientManager $cm */
$client = $cm->make([
        'host' => 'outlook.office365.com',
        'port' => 993,
        'encryption' => 'ssl', // 'tls',
        'validate_cert' => true,
        'username' => 'xyz@outlook.com',
        'password' => 'AccessToken',
        'protocol' => 'imap',
        'authentication' => "oauth",
]);

Credits: @EthraZa

Additional links: