So far you have spent considerable time with theory and configuration. Are you worried whether all you did actually leads to a working mail server? Before we do the final steps let’s take a break and verify that everything you did now works as expected.
At this point the /var/vmail directory should be empty or maybe contain an “example.org” directory if you played with the email@example.com account previously. You can get a list of all files and directories within by running:
Although there are not actually any emails on the server yet, you may still get somethinng along the lines of:
/var/vmail/ /var/vmail/lost+found /var/vmail/example.org /var/vmail/example.org/john /var/vmail/example.org/john/Maildir /var/vmail/example.org/john/Maildir/new /var/vmail/example.org/john/Maildir/subscriptions /var/vmail/example.org/john/Maildir/dovecot-uidvalidity /var/vmail/example.org/john/Maildir/tmp /var/vmail/example.org/john/Maildir/dovecot-uidvalidity.5a537e85 /var/vmail/example.org/john/Maildir/dovecot.mailbox.log /var/vmail/example.org/john/Maildir/dovecot-uidlist /var/vmail/example.org/john/Maildir/dovecot.index.log /var/vmail/example.org/john/Maildir/cur /var/vmail/example.org/john/Maildir/.INBOX.Trash /var/vmail/example.org/john/Maildir/.INBOX.Trash/new /var/vmail/example.org/john/Maildir/.INBOX.Trash/maildirfolder /var/vmail/example.org/john/Maildir/.INBOX.Trash/tmp /var/vmail/example.org/john/Maildir/.INBOX.Trash/dovecot-uidlist /var/vmail/example.org/john/Maildir/.INBOX.Trash/dovecot.index.log /var/vmail/example.org/john/Maildir/.INBOX.Trash/cur /var/vmail/example.org/john/Maildir/.INBOX.Junk /var/vmail/example.org/john/Maildir/.INBOX.Junk/new /var/vmail/example.org/john/Maildir/.INBOX.Junk/maildirfolder /var/vmail/example.org/john/Maildir/.INBOX.Junk/tmp /var/vmail/example.org/john/Maildir/.INBOX.Junk/dovecot-uidlist /var/vmail/example.org/john/Maildir/.INBOX.Junk/dovecot.index.log /var/vmail/example.org/john/Maildir/.INBOX.Junk/cur
Basically the schema you see here is /var/vmail/DOMAIN/USER/Maildir/…
Every IMAP mail folder then has three subdirectories:
- new – every file here is an email that was stored in this mail folder but not yet read
- cur – the same but for email that has been read already
- tmp – for temporary actions by the mail server
According to our Dovecot configuration the mail folders are nested like this:
- …/Maildir/new/… – the main inbox
- …/Maildir/.INBOX.reddit/new/… – the “reddit” mail folder below the inbox
- …/Maildir/.INBOX.servers.inga/new/… – the “servers”/”inga” mail folder below the inbox
If you do not use the legacy scheme with “separator = .” your directories will rather look like:
- …/Maildir/new/… – the main inbox
- …/Maildir/INBOX/reddit/new/… – the “reddit” mail folder below the inbox
- …/Maildir/INBOX/servers/inga/new/… – the “servers”/”inga” mail folder below the inbox
Send a test email
It is time to send a new emai linto the system. Open a new terminal window and run
tail -f /var/log/mail.log
to see what the mail server is doing. Now let’s send an email to John. A simple way to create and send an email is to pipe text to the “mail” command. Do that in another terminal window:
date | sendmail firstname.lastname@example.org
If all works as expected your mail.log will show a lot of technical information about the email delivery. Like this:
Jan 9 09:10:47 jen postfix/pickup: 30B4B41A98: uid=0 from=<root> Jan 9 09:10:47 jen postfix/cleanup: 30B4B41A98: message-id=<20180109081047.30B4B41A98@mail.example.org> Jan 9 09:10:47 jen postfix/qmgr: 30B4B41A98: from=<email@example.com>, size=287, nrcpt=1 (queue active) Jan 9 09:10:47 jen dovecot: lmtp(2636): Connect from local Jan 9 09:10:47 jen dovecot: lmtp(firstname.lastname@example.org): iHHHEwd5VFpMCgAA3BOsLQ: msgid=<20180109081047.30B4B41A98@mail.example.org>: saved mail to INBOX Jan 9 09:10:47 jen dovecot: lmtp(2636): Disconnect from local: Successful quit Jan 9 09:10:47 jen postfix/lmtp: 30B4B41A98: to=<email@example.com>, relay=mail.example.org[private/dovecot-lmtp], delay=0.28, delays=0.06/0.03/0.08/0.11, dsn=2.0.0, status=sent (250 2.0.0 <firstname.lastname@example.org> iHHHEwd5VFpMCgAA3BOsLQ Saved)
Your output will look slightly differently. Just focus on the parts that are printed in bold letters. They should be exactly the same in your log file. If everything worked as expected Postfix has accepted the email and forwarded it to Dovecot which in turn wrote the email in John’s maildir. If you get any errors in the log file then try to understand the error message and find the cause of the problem before you proceed.
Dovecot has now created a directory structure for John and created a new file:
/var/vmail/ […] /var/vmail/example.org/john/Maildir/new/1515485447.M404984P2636.mail,S=510,W=522 […]
The file may have a different name on your system – that’s okay. The file name printed in bold letter depicts the actual email file. It is the only file in the “new” folder.
Accessing the email as a file on disk
The file just contains the email:
Return-Path: <email@example.com> Delivered-To: firstname.lastname@example.org Received: from mail.example.org by mail.example.org (Dovecot) with LMTP id iHHHEwd5VFpMCgAA3BOsLQ for <email@example.com>; Tue, 09 Jan 2018 09:10:47 +0100 Received: bymail.example.org (Postfix, from userid 0) id 30B4B41A98; Tue, 9 Jan 2018 09:10:47 +0100 (CET) Message-Id: <20180109081047.30B4B41A98@mail.example.org> Date: Tue, 9 Jan 2018 09:10:47 +0100 (CET) From: firstname.lastname@example.org (root) Di 9. Jan 09:10:47 CET 2018
If anything went wrong then carefully check the last lines of your /var/log/mail.log. It will very likely point you to the problem. Or read the troubleshooting section. Or just add a comment to this page and ask other readers for help.
You can also use a slightly more comfortable tool to access Maildirs that will come handy for you as a mail server administrator: “mutt”.
mutt -f /var/vmail/example.org/john/Maildir
(You may get asked to create /root/Mail – this is standard procedure. Just press Enter.)
What you see now are the contents of John’s mailbox:
Using mutt is a nice way to check mailboxes while you are logged in to the mail server.
To reiterate what happens when you receive an email:
- Postfix receives the email (using the “sendmail” command in this example – but usually through the network using the SMTP protocol from other servers)
- Postfix talks to Dovecot via LMTP and hands over the email
- Dovecot write the email file to disk
Accessing the email via IMAP (Roundcube)
Now that the email has been delivered you can talk to Dovecot using the IMAP protocol to retrieve your email again. Are you still logged in via the Roundcube webmail interface? Then just reload and you will see the email:
Accessing the email via IMAP (mutt)
In the last section we used mutt to access the Maildir directly on disk. But remember that mutt also speaks IMAP:
mutt -f imaps://email@example.com@localhost
Does it show you the email now? Great.
Access the email through IMAP (desktop client)
Your users are not likely to use “mutt” to read their email – unless they are immortal console nerds. So of course you can use a graphical mail client to access John’s emails. If you use Thunderbird, Evolution, A**le Mail or some other IMAP client then feel free to configure a new IMAP account and connect to the server. Remember that the user name and email address are both “firstname.lastname@example.org” and the password is “summersun”.
POP3 versus IMAP
Aside from talking IMAP Dovecot also knows how to speak POP3. But let’s face it – POP3 is dead. I do not offer it to my users any more. But as your users may ask let’s quickly review the differences of the two protocols:
- POP3 (Post Office Protocol) is a simple protocol that lets you fetch email from a single mailbox. It is usually used to collect all emails, though you can also leave them on the server but this is a bit of a hack and you can’t create multiple folders on the server to sort your mail. It saves space on the mail server because the email gets moved to the user’s hard disk on their computer. But they won’t be able to access the same email from another computer. Besides you cannot create multiple folders on the server to sort your mail. There is just the inbox. This variant is antiquated and not exactly user-friendly.
- IMAP (Internet Messaging Application Protocol) is predominantly focused upon leaving your mail on the server but you can also collect it like POP3. The inbox is where your incoming emails are stored but users can also maintain folders and move emails to them. But users can move emails to different directories. IMAP is useful when you want to access your email from different locations without losing mail because you fetched it from another location. The drawback is that lazy users leave their mail on the server thus filling up your server’s hard disk (unless you use quotas).