brokenc0de/autodiscovery-mail-settings

Automatically discover mail settings from email or domain.

v1.0.0 2024-07-11 06:56 UTC

This package is auto-updated.

Last update: 2024-07-11 07:22:48 UTC


README

This PHP package provides functionality to auto-discover mail settings from a domain or email by looking up the settings from the Thunderbird autoconfig service.

Requirements

  • PHP 8.2 or higher
  • Laravel 8 or higher

Installation

You can install the package via Composer:

composer require brokencode/autodiscovery-mail-settings

Usage

Using the Class Directly

First, import the AutodiscoveryMailSettings class into your application:

use Brokencode\AutodiscoveryMailSettings\AutodiscoveryMailSettings;

Then, you can use the discover method to auto-discover mail settings for a given domain or email:

$autodiscovery = new AutodiscoveryMailSettings();

try {
    $settings = $autodiscovery->discover('example@example.com');
    print_r($settings);
} catch (InvalidDomainOrEmailException $e) {
    echo "Invalid domain or email: " . $e->getMessage();
} catch (MailSettingsNotFoundException $e) {
    echo "Mail settings not found: " . $e->getMessage();
} catch (MailSettingsFetchException $e) {
    echo "Error fetching mail settings: " . $e->getMessage();
}

Using the Facade

You can also use the Facade provided by the package.

use AutodiscoveryMailSettings;

try {
    $settings = AutodiscoveryMailSettings::discover('example@example.com');
    print_r($settings);
} catch (InvalidDomainOrEmailException $e) {
    echo "Invalid domain or email: " . $e->getMessage();
} catch (MailSettingsNotFoundException $e) {
    echo "Mail settings not found: " . $e->getMessage();
} catch (MailSettingsFetchException $e) {
    echo "Error fetching mail settings: " . $e->getMessage();
}

Exceptions

The package throws specific exceptions for different error conditions:

  • InvalidDomainOrEmailException: Thrown when the provided domain or email is invalid.
  • MailSettingsNotFoundException: Thrown when mail settings could not be found for the given domain.
  • MailSettingsFetchException: Thrown when there is an error fetching the mail settings.

Testing

This package uses the PEST testing framework. You can run the tests with the following command:

vendor/bin/pest