Testing IMAP

You have already finished the configuration of Dovecot so fetching emails using the IMAP protocol will already work. Let’s give it a try using a simple but powerful IMAP client: mutt.

mutt -f imaps://john@example.org@webmail.example.org

The connection URL may look a little confusing because of the two “@” characters. Usually mutt expects the format imaps://user@server. And as we use the email address as the “user” part you get this look.

You should get prompted for the password which is “summersun”. If you get any certificate warnings then check if you used the correct server name to connect to and if you finished the certificate/LetsEncrypt part earlier in this guide.

After logging in you will see an empty inbox:

Very good – so IMAP connections and authentication works. Exit mutt by pressing “q”.

33 thoughts on “Testing IMAP”

  1. John Bergquist

    Struggling here… Everything works flawlessly up to this point with a fresh install. IMAP is failing with the following error when I input the mutt command:

    (ran “systemctl status dovecot” to see this)
    Dec 29 10:48:31 webmail systemd[1]: Started Dovecot IMAP/POP3 email server.
    Dec 29 10:48:31 webmail dovecot[1632]: master: Dovecot v2.3.4.1 (f79e8e7e4) starting up for imap, lmtp, sieve, pop3 (core dump
    Dec 29 10:50:07 webmail dovecot[1636]: auth: Fatal: sqlpool: Missing value in connect string: password
    Dec 29 10:50:07 webmail dovecot[1632]: master: Error: service(auth): command startup failed, throttling for 2 secs
    Dec 29 10:50:07 webmail dovecot[1636]: imap-login: Disconnected: Auth process broken (disconnected before auth was ready, wait
    Dec 29 10:50:07 webmail dovecot[1636]: imap-login: Warning: Timeout leak: 0x7f699e0c9140 (auth-server-connection.c:397)

    It is looking for a password. I’ve been back through everything up to this point and don’t find any coding errors. I also didn’t find any code to set up the IMAP protocol. What am I missing? Thanks!

    1. Christoph Haas

      Please take a look at /etc/dovecot/dovecot-sql.conf.ext and check if you defined the password for the “mailserver” user in the “connect” line.

  2. John Bergquist

    This is what that code looks like:

    driver = mysql
    connect = host=127.0.0.1 dbname=mailserver user=mailserver password = (my password for mailserver)
    user_query = SELECT email as user, \
    concat(‘*:bytes=’, quota) AS quota_rule, \
    ‘/var/vmail/%d/%n’ AS home, \
    5000 AS uid, 5000 AS gid \
    FROM virtual_users WHERE email=’%u’;
    password_query = SELECT password FROM virtual_users WHERE email=’%u’;

    I deleted my actual password for sane reasons, but did verify that it was correct…

    1. John Bergquist

      nevermind. Found it. I had a space before and after the “=” for the password. I believe your code has them also in this guide…

  3. Adon Irani

    I see my current mail server has default_pass_scheme = SHA512
    This IMAP test only succeeds If i add that to dovecot-sql.conf.ext.

    Other than having all my users reset their passwords, am I safe to just leave this scheme as-is? Also, do i need to make changes elsewhere to ensure all future accounts have a consistent password scheme?

    1. Christoph Haas

      You can make the encryption scheme explicit per user. Just add the scheme to the beginning of the password. Examples:

      {CRAM-MD5}asldfhasdmofuzsapduif…
      {PLAIN-MD5}sapjhapmsdofzuma…
      {SHA256-CRYPT}asöldfimapsdio…
      {BLF-CRYPT}apodisfhpasduio…

      That way no matter what you set as “default_pass_scheme” Dovecot will always now how to check the password against the hash with the right algorithm.

  4. root@server:/var/www# systemctl status dovecot
    ● dovecot.service – Dovecot IMAP/POP3 email server
    Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Sun 2020-01-12 02:39:13 CET; 3min 24s ago
    Docs: man:dovecot(1)
    http://wiki2.dovecot.org/
    Process: 27763 ExecStart=/usr/sbin/dovecot -F (code=exited, status=89)
    Main PID: 27763 (code=exited, status=89)

    Jan 12 02:39:13 ispmail systemd[1]: Started Dovecot IMAP/POP3 email server.
    Jan 12 02:39:13 ispmail dovecot[27763]: doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/15-mailboxes.conf line 45: Unknown setting: mailbox { mailbox
    Jan 12 02:39:13 ispmail dovecot[27763]: doveconf: Error: managesieve-login: dump-capability process returned 89
    Jan 12 02:39:13 ispmail dovecot[27763]: doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/15-mailboxes.conf line 45: Unknown setting: mailbox { mailbox
    Jan 12 02:39:13 ispmail systemd[1]: dovecot.service: Main process exited, code=exited, status=89/n/a
    Jan 12 02:39:13 ispmail systemd[1]: dovecot.service: Failed with result ‘exit-code’.

    1. Christoph Haas

      See the /usr/share/dovecot/conf.d/15-mailboxes.conf file on your disk. That’s the original version. Maybe you can spot where your config has an error.

  5. Hallo Christoph,

    mutt -f imaps://xxx@attinetworks.de@webmail.attinetworks.de
    Kann keine Verbindung zu webmail.attinetworks.de aufbauen (Unterbrechung während des Betriebssystemaufrufs).

    Was könnte diese Fehlermeldung bedeuten? Bin Deinem Tutorial bis hierhin minutiös gefolgt.

    VG,
    toby

  6. I don’t know why. Email are received only maybe 10 min after sending and some email are just not incoming.

    1. Well that’s ok. I just realized I had a DNS misconfiguration. Well I had MX record redirect to mail.domain.ltd. but as following this guide, it may have better being webmail.domain.ltd.

      After that change email are welcome and incoming correctly.

  7. Matt Penfold

    I am getting an connection refused error when I run mutt -f imaps://john@example.org@webmail.example.org (modified to point to my mail server FQDN).

    Where should I start looking for why that is happening?

    1. Matt Penfold

      Found it. I had forgotten to forward the relevant ports on the router. Too early in the day with too little tea!

  8. Hello Christoph,

    Thank you very much for amazing instructions.
    Could you please help me as I faced error which I can not fix.
    When I try mutt it fails and dovecot reports back:
    imap-login: Error: Failed to initialize SSL server context: Couldn’t parse private SSL server context: Couldn’t parse private SSL key: error:0909006C:PEM routines:get_name:no start line: Expecting: ANY PRIVATE KEY: user=, rip=192.168.0.1, lip=192.168.0.79

    https part works perfectly – no problems at all…

  9. Rita Burrows

    CORRECTION – I realised my error message runs over two lines:

    Sep 20 18:04:25 raspberrypi dovecot: auth-worker(12830): Error: sql(xxx@xxxonline.com,86.176.xxx.xx,): Invalid password in passdb: Not a valid MD5-CRYPT or PLAIN-MD5 password
    Sep 20 18:04:27 raspberrypi dovecot: imap-login: Disconnected (auth failed, 1 attempts in 6 secs): user=, method=PLAIN, rip=86.176.xxx.xx, lip=192.168.1.xxx, TLS, session=

  10. Hi Cristoph,
    when i Try to test imaps the request fail:

    pi@hermes:~ $ mutt -f imaps://test@desimoneict.com@webmail.desimoneict.com
    Impossibile connettersi a webmail.desimoneict.com (Chiamata di sistema interrotta).

    pi@hermes:~ $ systemctl status dovecot
    ● dovecot.service – Dovecot IMAP/POP3 email server
    Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
    Active: active (running) since Sun 2020-10-04 14:50:10 CEST; 14min ago
    Docs: man:dovecot(1)
    http://wiki2.dovecot.org/
    Main PID: 25250 (dovecot)
    Tasks: 4 (limit: 2065)
    CGroup: /system.slice/dovecot.service
    ├─25250 /usr/sbin/dovecot -F
    ├─25252 dovecot/anvil
    ├─25253 dovecot/log
    └─25254 dovecot/config

    ott 04 14:50:10 hermes systemd[1]: Started Dovecot IMAP/POP3 email server.
    ott 04 14:50:10 hermes dovecot[25250]: master: Dovecot v2.3.4.1 (f79e8e7e4) starting up for imap, lmtp, sieve, pop3 (core dump

    my record mx is “10 hermes.desimoneict.com.”

    when instead I try to connetct to imap:

    mutt -f imap://test@desimoneict.com@webmail.desimoneict.com
    Password per test@desimoneict.com@webmail.desimoneict.com:

    where could I look to solve?

    1. Christoph Haas

      Maybe you figured it out already? When I run the “mutt” command you mentioned I get a connection.

  11. BenEspersen

    Good evening,
    im from Germany.
    I tried to connect via mutt with a lot of changed vars. And I had two cases and I want to know whether there is a difference between them:
    1. I tried to connect and I had to enter my password. The mut view closed and I were in my shell again.
    2. I tried to connect and I had to enter my password. The mut view closes and the shell says: “Anmeldung gescheitert” (in English it should be “connection refused”).
    Does the answer make a difference?
    Best wishes, Ben.

  12. JackMeinoff

    This works fine from Mutt but I can’t seem to get IMAP to connect otherwise from any clients. The password isn’t the issue, they just seem to time out though I’m not using the firewall and the ports are being listened too on 0.0.0.0

  13. Hi Christoph,

    I’m having some trouble with this step. When running the above command, mutt responds with the message “Could not connect to webmail.sergiomoraes.com (Connection refused).”

    The full command plus response from the command line:

    $ mutt -f imaps://john@example.org@webmail.sergiomoraes.com
    Could not connect to webmail.sergiomoraes.com (Connection refused).
    Could not connect to webmail.sergiomoraes.com (Connection refused).

    Any advice would be greatly appreciated.
    Thank you!

      1. Thank you for the prompt reply! It seems like it was a router port configuration mistake on my end. I was able to connect after making some adjustments.

  14. Hi Christoph and thanks a lot for the extensive tutorial!
    One thing I don’t understand: I connect to mutt with `mutt -f imaps://john@example.org@webmail.example.org`– so where does the sub-domain “webmail” come from? Was it configured before, I might be blind but I just can’t find where…
    Thing is, I don’t want to run any webmail, just plain IMAP access, and that seems to work fine with when I enter just “example.org” for IMAP and SMTP servers.
    Sorry for bothering and thanks for any hint,
    Boris

    1. I just found out another little piece of my puzzle(dness): I believe that mutt doesn’t care for the sub-domain, except that it checks for the according certificate – is that so? If I had certificates for webmail.example.org, mail.example.org and pizza.example.org, then I could run mutt with any of these domain names? mutt -f imaps://john@example.org@pizza.example.org would work as well?

  15. Hey Christoph, it’s me again. 🙂

    Do you have any idea what can cause the following error when I try to test IMAP using mutt?

    $ mutt -f imaps://john@example.org@webmail.sergiomoraes.com
    No authenticators available or wrong credentials

    I’m pretty sure the credentials are correct (I retraced my steps through the tutorial to confirm it). Thoughts?

    Thank you.

  16. struggling with this part. I tried doveadm:

    root@server01:/var/log/private# doveadm -Dvvvv auth test john@example.org summersun
    Debug: Loading modules from directory: /usr/lib/dovecot/modules
    Debug: Module loaded: /usr/lib/dovecot/modules/lib10_quota_plugin.so
    Debug: Loading modules from directory: /usr/lib/dovecot/modules/doveadm
    Debug: Skipping module doveadm_acl_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_acl_plugin.so: undefined symbol: acl_user_module (this is usually intentional, so just ignore this message)
    Debug: Skipping module doveadm_expire_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_expire_plugin.so: undefined symbol: expire_set_deinit (this is usually intentional, so just ignore this message)
    Debug: Module loaded: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_quota_plugin.so
    Debug: Module loaded: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_sieve_plugin.so
    Debug: Skipping module doveadm_fts_lucene_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib20_doveadm_fts_lucene_plugin.so: undefined symbol: lucene_index_iter_deinit (this is usually intentional, so just ignore this message)
    Debug: Skipping module doveadm_fts_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib20_doveadm_fts_plugin.so: undefined symbol: fts_user_get_language_list (this is usually intentional, so just ignore this message)
    Debug: Skipping module doveadm_mail_crypt_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/libdoveadm_mail_crypt_plugin.so: undefined symbol: mail_crypt_box_get_pvt_digests (this is usually intentional, so just ignore this message)
    passdb: john@example.org auth failed
    extra fields:
    user=john@example.org

    …i dutifully ignore the messages that are safe to ignore, module probably not loaded or whatever. But it seems to me like it isn’t reading passdb at all.

    When I try on mutt, first message is “/root/Mail doesn’t exist, you wanna create”? which i expect is normal and can be ignored. I see it connect on TLS1.3, very good. It prompts for password, which is {BLF-CRYPT}yadayadayada123whatever after using the hashing tool earlier in the guide. I see:
    “Authentication (PLAIN)” [huh??]
    “Logging In”
    “Login Failed”

    I try with a plaintext password in the db. Same thing. Any pointers?

    1. OK, the issue was (i) the hashing algorithm and (ii) iptables it seems.
      (i)
      I generated a new password without specifying BLF-CRYPT –
      root@server: /#doveadm pw
      Enter new password:
      Retype new password:
      {CRYPT}$2y$bla123bla123bla123.123.Bla
      I entered this into the password field in the virtual_user table.

      It seems to use bcrypt by default from version 2.3 onward, I am happy enough with that.
      (ii)
      I must also admin I had iptables rule to drop all INPUT except for established and related connections, my remote terminal and src/dst 127.0.0.1 – this may have interfered with connecting to mysql. Now I set up a firewall in my vps panel, use cloudflare’s dns and nameservers to block geoip of everywhere except my vps location and flushed iptables.

      So now I can log in via Mutt and all is well.

      Thanks again for a fabulous tutorial!

  17. Patrik Fältström

    I also had issues with systemd that had protection for the dovecot process. This fixed it, i.e. turn off protection:

    # cat /etc/systemd/system/dovecot.service.d/service.conf
    [Service]
    ProtectSystem=false

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top