# maildiscover

> Simple python library for email connection parameters discovery

## What for?

This library aims to provide a simple way to retrieve email configuration
parameters (for `SMTP`/`submission`, `POP3` and `IMAP` servers). Currently, it
does so implementing the [autoconfig][ac] Mozilla protocol and a special
[dns][dns] lookup.

*NOTE*: I also considered trying to implement the [autodiscover][ad] flow from
Microsoft, but I wasn't able to make it work.


[ac]: https://wiki.mozilla.org/Thunderbird:Autoconfiguration
[dns]: https://datatracker.ietf.org/doc/html/rfc6186
[ad]: https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/autodiscover-for-exchange

## How to use it?

Install its latest version from pypi

```sh
pip install maildiscover
```

Then, import it into your project. You can either use the provided `get`
function, that tries all the known methods and returns a merged version of the
found data:

```python
import maildiscover

result = maildiscover.get("myself@example.com")
```

Or you can use any specific method independently

```python
import maildiscover

dns_method = maildiscover.DNSSRV("myself@example.com")
ac_method = maildiscover.Autoconfig("myself@example.com")

dns_result = dns_method.get()
ac_result = ac_method.get()
```

The method may raise, either if it fails (in such case they raise
`MethodFailed`) or if the provided email is malformed, then they raise
`MaformedEmail`.

In case of success, the returned data is a custom dataclass, that can be
converted back to a dict with the `to_dict` method, with self-explaining
fields.

## Contacts

If you want to suggest a change or propose a patch, don't hesitate to drop me an
email at `blallo -|AT|- autistici.org`. I am friendly :)
