承接 accountdesk/mail-autodetect 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

accountdesk/mail-autodetect

Composer 安装命令:

composer require accountdesk/mail-autodetect

包简介

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

README 文档

README

Latest Version Total Downloads License PHP Version CI

Mail server discovery on autopilot

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

Installation

Option 1: Composer

composer require accountdesk/mail-autodetect

Option 2: Manual

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

require_once 'path/to/AutoDetector.php';

Requirements:

  • PHP >= 8.1
  • ext-curl
  • ext-simplexml

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

$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)

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

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

Detection Strategies

The library uses multiple strategies in descending reliability:

# Strategy Score Description
1 Mozilla ISPDB 95 Thunderbird autoconfig database
2 Known MX 92 Known providers (Gmail, Outlook, etc.) via MX pattern
3 Microsoft Autodiscover 92 Exchange/Office 365 (requires email)
4 DNS SRV 90 RFC 6186 service records
5 Domain Autoconfig 90 autoconfig.domain/mail/config-v1.1.xml
6 MX Heuristic 75-80 MX record + SPF parsing + TCP check
7 Standard Hosts 55-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

Each candidate contains:

Field Type Description
host string Server hostname
port int Port (993, 465, 587, ...)
ssl string ssl, starttls, or plain
auth string|null Auth method (if known)
source string Primary source
sources array All sources that found this server
score int Confidence score (0-100)
match_count int Number of sources

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

MIT

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.

accountdesk/mail-autodetect 适用场景与选型建议

accountdesk/mail-autodetect 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mail」 「email」 「smtp」 「imap」 「autodiscover」 「autoconfig」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 accountdesk/mail-autodetect 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 accountdesk/mail-autodetect 我们能提供哪些服务?
定制开发 / 二次开发

基于 accountdesk/mail-autodetect 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-23