horde/mail_autoconfig
Composer 安装命令:
composer require horde/mail_autoconfig
包简介
Mail server autoconfiguration library
关键字:
README 文档
README
Mail server auto-discovery library for IMAP, POP3, and SMTP.
Overview
Horde Mail_Autoconfig discovers mail server configuration (hostnames, ports, TLS settings) for a given email address. It ships two independent codepaths:
- PSR-4 Modern API (
Horde\Mail\Autoconfig\Autoconfig). Uses typed value objects, PSR-18 HTTP Client, injectable DNS resolver plugins. - PSR-0 Legacy API (
Horde_Mail_Autoconfig) The backward-compatible option. UsesHorde_Http_ClientandNetDNS2\Resolverdirectly.
Both codepaths coexist in the same package (src/ and lib/). There is no
forwarding layer between them. Each is a standalone entry point.
It currently supports IMAP, POP3 and SMTP protocols.
Installation
composer require horde/mail_autoconfig
Quick Start (PSR-4)
use Horde\Mail\Autoconfig\Autoconfig; use Horde\Mail\Autoconfig\Dns\NetDns2Resolver; use Horde\Mail\Autoconfig\ServerType; use Horde\Mail\Autoconfig\ValidationMode; $dns = new NetDns2Resolver(); $http = /* any PSR-18 ClientInterface */; $rf = /* any PSR-17 RequestFactoryInterface */; $autoconfig = Autoconfig::withBuiltinDrivers($dns, $http, $rf) ->withValidation($myValidator, ValidationMode::Next); $result = $autoconfig->discover('user@example.com'); $imap = $result->firstOfType(ServerType::Imap);
withBuiltinDrivers() wires the three built-in drivers (SRV, Thunderbird
ISPDB, hostname guessing). withValidation() adds optional server validation plugins (only interface and null implementation shipped).
Pass your ValidatorInterface implementation and a mode:
- Next (default): Skip servers that fail validation, keep the rest
- Fatal: Throw
AutoconfigExceptionon the first failure - None: Skip validation entirely
Both methods return new instances; the originals are never modified.
Without withValidation(), all discovered servers are returned as-is.
Narrowed Searches
// Submission (SMTP/MSA) servers only $msa = $autoconfig->discoverMsa('user@example.com'); // Incoming mail only, skip POP3 $mail = $autoconfig->discoverMail('user@example.com', noPop3: true);
Working with Results
// First IMAP server, or null $imap = $result->firstOfType(ServerType::Imap); // All submission servers as a new DiscoveryResult $submissionOnly = $result->ofType(ServerType::Submission);
Custom Driver Sets
When you need to go beyond the defaults:
- Drop a driver
- add your own
- or wire drivers with non-default options
Use the constructor directly:
use Horde\Mail\Autoconfig\Driver\SrvDriver; use Horde\Mail\Autoconfig\Driver\ThunderbirdDriver; // SRV + Thunderbird only, no hostname guessing $autoconfig = new Autoconfig( new SrvDriver($dns), new ThunderbirdDriver($http, $rf), ); // Chaining still works $validated = $autoconfig->withValidation($myValidator);
Quick Start (PSR-0 Legacy)
$autoconfig = new Horde_Mail_Autoconfig(); // Returns the first valid server or false $imap = $autoconfig->getMailConfig('user@example.com', [ 'auth' => $password, ]); $smtp = $autoconfig->getMsaConfig('user@example.com', [ 'auth' => $password, ]);
Discovery Drivers
withBuiltinDrivers() registers these drivers in the order shown:
| Driver | Strategy |
|---|---|
SrvDriver |
RFC 6186 / RFC 8314 DNS SRV records |
ThunderbirdDriver |
Mozilla ISPDB autoconfig XML |
GuessDriver |
Common hostname patterns + DNS A/AAAA validation |
SRV Records (RFC 6186 + RFC 8314)
Queries these service names per domain:
| Service | Type | TLS |
|---|---|---|
_imaps._tcp |
IMAP | Implicit TLS (993) |
_imap._tcp |
IMAP | STARTTLS (143) |
_pop3s._tcp |
POP3 | Implicit TLS (995) |
_pop3._tcp |
POP3 | STARTTLS (110) |
_submissions._tcp |
Submission | Implicit TLS (465) |
_submission._tcp |
Submission | STARTTLS (587) |
Thunderbird ISPDB
Tries these URLs in order (all HTTPS):
https://autoconfig.{domain}/mail/config-v1.1.xml?emailaddress={email}https://{domain}/.well-known/autoconfig/mail/config-v1.1.xmlhttps://autoconfig.thunderbird.net/v1.1/{domain}
Hostname Guessing
Tries common prefixes (smtp., mail., imap., pop., pop3.) against
each domain and keeps only hostnames that resolve in DNS.
Key Differences: PSR-4 vs PSR-0
| Aspect | PSR-4 (src/) |
PSR-0 (lib/) |
|---|---|---|
| Return type | DiscoveryResult (all servers) |
First valid server or false |
| Validation | Caller's responsibility | Built-in (connects to test) |
| HTTP client | PSR-18 ClientInterface |
Horde_Http_Client |
| DNS resolver | DnsResolverInterface (injectable) |
NetDNS2\Resolver (direct) |
| TLS modes | TlsMode enum |
'tls' string or null |
| Server types | ServerType enum |
Class hierarchy |
| RFC 8314 | _submissions._tcp supported |
Not supported |
| ISPDB URL | autoconfig.thunderbird.net |
autoconfig.thunderbird.net |
System Requirements
- PHP ^8.1
- ext-SimpleXML
horde/mail^3mikepultz/netdns2^2.0 for the DNS probes- A PSR-18 HTTP client and PSR-17 request factory (for
src/drivers)
Testing
# Unit tests phpunit --testsuite unit # Full suite (integration tests need test/conf.php) phpunit
Integrator and Developer Guides
See doc/UPGRADING.md for detailed migration instructions from the PSR-0 API to the PSR-4 API.
See doc/EXTENDING.md for how to add validation of found configs or additional check drivers.
License
LGPL-2.1-only -- see LICENSE for details.
Links
horde/mail_autoconfig 适用场景与选型建议
horde/mail_autoconfig 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 839 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 12 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「smtp」 「imap」 「autodiscovery」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 horde/mail_autoconfig 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horde/mail_autoconfig 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 horde/mail_autoconfig 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP class to access an IMAP mailbox. Specifically uses the Laminas library and not the IMAP extension.
yii2 extension to read and process mails from IMAP and PHP
IMAP client for PHP without php-imap extension dependency
Creates a lock file containing all the packages which are auto-discovered by Laravel.
Laravel IMAP client
The Message Submission Agent Diagnostics tool (msadiag) facilitates testing the compatibility of third party message submission agents.
统计信息
- 总下载量: 839
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: LGPL-2.1-only
- 更新时间: 2023-12-04