How to setup auto-configure email for Android Mail app on your server

androidautoconfigurationautodiscoveryemail

I work for a local ISP, Web and Email Hosting provider. I've been able to setup autoconfig/autodiscover and .mobileconfig for Thunderbird, Outlook, and IOS, respectively. This covers most of our user-base, except for beloved Android. It's tested. It works. We're using it regularly.

How can we setup something similar for Android? So far, the only option seems to be requesting the user to install a third-party app such as Outlook from the Play Store.

There has to be a way for this to work on the built-in Android Mail app.

To be explicit, our setup is as follows:

IMAP: port 993, SSL, plain password (by default protected by the SSL)
SMTP: port 465, SSL, plain password (by default protected by the SSL)

Both server names are the same, but differ from the domain in the email address.

Username is the full email address.

We have many domains under our belt, so setting up DNS specifics for each domain is expensive in terms of man-power.

The ones we have delineated work well, and are universal in terms of DNS, so no DNS records needed to be added or changed, meaning we could just offer it up as part of our service and it would cover all our clientele.

Their has to be something similar for Android by now.

Is there a way to auto-configure the settings for Android Mail app based on just the email address and password yet?

Still no answers on this.

Does anyone know what Android Mail is checking when it says its attempting to automically check for settings?

Best Answer

I wrote up autoconfig (Thunderbird/Mozilla standard) + autodiscover (Microsoft standard) and RFC 6186 as an Ansible 'role' - but with plenty of text to explain what's going on. Summary: Setup RFC 6186 first to see if that is sufficient, and setup the others if that's not enough.

Here's extracts from the role's explanation; see the Ansible role for more info, and the rest of the text there - it should be comprehensible even if you don't know Ansible (esp. see tasks and templates directories); further down you'll find how to test autoconfig / autodiscover setups:

RFC 6186

In case you're not aware of RFC 6186, my advice is: Setup RFC 6186 records for your domain before bothering with autodiscover/autoconfig: This is a simpler and more modern way of configuring autodiscover/autoconfig via DNS SRV records; set that up first before using this role, which is really to provide completeness so that [esp. legacy] email clients that aren't RFC-6186-aware can still find their configuration. If you're after a quick-fix for autodiscover/autoconfig, setup RFC-6186 first - for example in your domain's zone file (from the RFC),

_imap._tcp       SRV  0 1 143 imap.example.com.
_pop3._tcp       SRV 10 1 110 pop3.example.com.
_submission._tcp SRV  0 1 587 mail.example.com.

If you still need autodiscover/autoconfig after setting up RFC 6186 records for your domain, read on...

Requirements

For Microsoft autodiscover: PHP (edit: I've used PHP in the Ansible role; other server-side languages are available...) (the XML template needs to generate the <LoginName> field based on supplied POST data from the mail client's web query).

Except for a simple single-domain setup, some DNS setup may be needed. A possible DNS setup might look like this,

  • Thunderbird: autoconfig.example.org CNAME--> some.central.domain
  • Microsoft: _autodiscover._tcp.example.org SRV --> some.central.domain

in named/BIND syntax for a given zone/domain, that would be,

autoconfig          IN      CNAME           some.central.domain
_autodiscover._tcp  IN      SRV     0 0 443 some.central.domain

Testing autoconfig

Once you've setup a host for autoconfig with this role, you can test the result by issuing command-line requests such as,

curl http://autoconfig_target_domain/.well-known/autoconfig/mail/config-v1.1.xml
curl http://autoconfig_target_domain/mail/config-v1.1.xml

where autoconfig_target_domain refers to the target domain of a DNS CNAME record for _autoconfig._tcp.your_domain, or for simpler setups (without SRV record) may just be your_domain and/or autoconfig.your_domain.

Testing autodiscover

Once you've setup a host for autodiscover with this role, you can test the result by issuing a command-line POST request such as,

curl -XPOST -d @req.xml --header "Content-Type:text/xml" https://autodiscover_target_domain/autodiscover/autodiscover.xml

where autodiscover_target_domain refers to the target domain of a DNS SRV record for _autodiscover._tcp.your_domain, or for simpler setups (without SRV record) may just be your_domain and/or autodiscover.your_domain.

where req.xml looks like this,

<?xml version="1.0" encoding="utf-8"?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
  <Request>
    <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
    <EMailAddress>someone@your.domain.here</EMailAddress>
  </Request>
</Autodiscover>

esp. helpful on getting this right was this site.