PHPackages                             accountdesk/mail-autodetect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. accountdesk/mail-autodetect

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

accountdesk/mail-autodetect
===========================

Auto-detect IMAP and SMTP mail server settings for any domain

0.3.0(3mo ago)13MITPHPPHP &gt;=8.1CI passing

Since Jan 24Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/accountdesk/mail-autodetect)[ Packagist](https://packagist.org/packages/accountdesk/mail-autodetect)[ Docs](https://github.com/accountdesk/mail-autodetect)[ RSS](/packages/accountdesk-mail-autodetect/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Mail-AutoDetect
===============

[](#mail-autodetect)

[![Latest Version](https://camo.githubusercontent.com/e8ee42c1a9aa21e1a8fa0b57e7f53de17be6731df181b3fff104709c66eaf631/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6163636f756e746465736b2f6d61696c2d6175746f646574656374)](https://packagist.org/packages/accountdesk/mail-autodetect)[![Total Downloads](https://camo.githubusercontent.com/0bba40650305491e7230896a76624b14e29352a9617e6ee10633f2f2a2d0304b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6163636f756e746465736b2f6d61696c2d6175746f646574656374)](https://packagist.org/packages/accountdesk/mail-autodetect)[![License](https://camo.githubusercontent.com/961da298e3484bed14e8edec9220af3d35fdd14d4bf62b340a84fd92b560dc66/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6163636f756e746465736b2f6d61696c2d6175746f646574656374)](https://packagist.org/packages/accountdesk/mail-autodetect)[![PHP Version](https://camo.githubusercontent.com/f9d4a64f1df586463bcda6e734ce8f2c07738a5197e298433e055d78c0c4423c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6163636f756e746465736b2f6d61696c2d6175746f646574656374)](https://packagist.org/packages/accountdesk/mail-autodetect)[![CI](https://github.com/accountdesk/mail-autodetect/actions/workflows/ci.yml/badge.svg)](https://github.com/accountdesk/mail-autodetect/actions/workflows/ci.yml)

> *Mail server discovery on autopilot*

PHP library for automatic detection of IMAP and SMTP server settings for any domain.

Installation
------------

[](#installation)

### Option 1: Composer

[](#option-1-composer)

```
composer require accountdesk/mail-autodetect
```

### Option 2: Manual

[](#option-2-manual)

Copy `src/AutoDetector.php` into your project and include it:

```
require_once 'path/to/AutoDetector.php';
```

**Requirements:**

- PHP &gt;= 8.1
- ext-curl
- ext-simplexml

Usage
-----

[](#usage)

```
use MailAutodetect\AutoDetector;

$detector = new AutoDetector();

// With email address (recommended - enables Microsoft Autodiscover)
$result = $detector->autoDetect('user@example.com');

// With domain only (without Autodiscover)
$result = $detector->autoDetect('gmail.com');

print_r($result);
```

**Output:**

```
[
    'imap' => [
        [
            'host' => 'imap.gmail.com',
            'port' => 993,
            'ssl' => 'ssl',
            'auth' => 'OAuth2',
            'source' => 'mozilla_ispdb',
            'score' => 95,
            'sources' => ['mozilla_ispdb'],
            'match_count' => 1,
        ],
        // more candidates...
    ],
    'smtp' => [
        [
            'host' => 'smtp.gmail.com',
            'port' => 465,
            'ssl' => 'ssl',
            'auth' => 'OAuth2',
            'source' => 'mozilla_ispdb',
            'score' => 95,
            'sources' => ['mozilla_ispdb'],
            'match_count' => 1,
        ],
        // more candidates...
    ],
]
```

Configuration
-------------

[](#configuration)

```
$detector = new AutoDetector([
    'timeout_http' => 10,  // HTTP requests (default: 10s)
    'timeout_tcp'  => 3,   // TCP connections (default: 3s)
    'logger'       => $logger,  // PSR-3 logger (optional)
]);

// Threshold: stop early when IMAP+SMTP with score > threshold found
$result = $detector->autoDetect('example.com', threshold: 90);
```

### Logging (PSR-3)

[](#logging-psr-3)

```
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('mail-autodetect');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));

$detector = new AutoDetector(['logger' => $logger]);
```

Log levels:

- `info`: Start/end of detection, threshold reached
- `debug`: Individual strategies, DNS/HTTP requests, cache hits
- `warning`: HTTP/DNS errors

### Caching

[](#caching)

DNS and HTTP results are automatically cached (in-memory per request). Multiple queries for the same domain won't trigger duplicate requests.

Detection Strategies
--------------------

[](#detection-strategies)

The library uses multiple strategies in descending reliability:

\#StrategyScoreDescription1Mozilla ISPDB95Thunderbird autoconfig database2Known MX92Known providers (Gmail, Outlook, etc.) via MX pattern3Microsoft Autodiscover92Exchange/Office 365 (requires email)4DNS SRV90RFC 6186 service records5Domain Autoconfig90`autoconfig.domain/mail/config-v1.1.xml`6MX Heuristic75-80MX record + SPF parsing + TCP check7Standard Hosts55-70`imap.domain`, `smtp.domain` + TCP check**Score calculation:**

- Servers found by multiple sources get +5 bonus per additional source
- Reverse DNS mismatch on guessed hosts: -15 points
- Maximum: 100 points

Response Format
---------------

[](#response-format)

Each candidate contains:

FieldTypeDescription`host`stringServer hostname`port`intPort (993, 465, 587, ...)`ssl`string`ssl`, `starttls`, or `plain``auth`string|nullAuth method (if known)`source`stringPrimary source`sources`arrayAll sources that found this server`score`intConfidence score (0-100)`match_count`intNumber of sourcesSecurity Considerations
-----------------------

[](#security-considerations)

> **Important:** This library detects mail server configurations but does NOT validate them.

Before using detected settings with real credentials:

1. **Always confirm with the user** - Show the detected hostname/port and ask for explicit confirmation
2. **Don't auto-connect** - Never automatically test connections with real passwords
3. **Validate the domain** - Ensure the detected hosts belong to the expected domain

Example secure implementation:

```
$result = $detector->autoDetect($email);
$imap = $result['imap'][0] ?? null;

if ($imap) {
    // Show user the detected settings and ask for confirmation
    echo "Detected IMAP server: {$imap['host']}:{$imap['port']}\n";
    echo "Is this correct? (y/n): ";

    if (readline() !== 'y') {
        // Let user enter settings manually
    }
}
```

**Why this matters:** A malicious domain could configure autoconfig/autodiscover to point to an attacker-controlled server, potentially capturing credentials.

License
-------

[](#license)

MIT

Testing
-------

[](#testing)

This library uses static analysis (Mago) instead of unit tests. Network-dependent libraries like this are better validated through real-world usage than mocked tests.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance80

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

108d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ceaa4ed9c1efb68fc5fc1aa37cb75289841dafead4e812768e910841711a47b2?d=identicon)[mathe42](/maintainers/mathe42)

---

Top Contributors

[![mathe42](https://avatars.githubusercontent.com/u/24830662?v=4)](https://github.com/mathe42 "mathe42 (10 commits)")

---

Tags

autofilldetectionemailimapsmtpmailemailsmtpimapautodiscoverautoconfig

### Embed Badge

![Health badge](/badges/accountdesk-mail-autodetect/health.svg)

```
[![Health](https://phpackages.com/badges/accountdesk-mail-autodetect/health.svg)](https://phpackages.com/packages/accountdesk-mail-autodetect)
```

###  Alternatives

[ddeboer/imap

Object-oriented IMAP for PHP

9153.9M11](/packages/ddeboer-imap)[mlocati/spf-lib

Parse, build and validate SPF (Sender Policy Framework) DNS records

67867.9k2](/packages/mlocati-spf-lib)[pear/net_smtp

An implementation of the SMTP protocol

263.0M16](/packages/pear-net-smtp)[henrique-borba/php-sieve-manager

A modern (started in 2022) PHP library for the ManageSieve protocol (RFC5804) to create/edit Sieve scripts (RFC5228). Used by Cypht Webmail.

23125.7k2](/packages/henrique-borba-php-sieve-manager)[thefox/smtpd

SMTP server (library) written in pure PHP.

1302.4k1](/packages/thefox-smtpd)[benhall14/php-imap-reader

A PHP class that makes working with IMAP in PHP simple.

3516.6k](/packages/benhall14-php-imap-reader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
