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 all you did works so far.
At this point the /var/vmail directory should be empty or maybe contain an “example.org” directory if you played with the firstname.lastname@example.org account previously. You can get a list of all files and directories within by running:
There may be nothing except perhaps a “lost+found” directory if /var/vmail is on a separate partition. And perhaps skeleton files like “.profile” or “.bashrc”.
If you added test data to the database in the section about database preparation as you were told then you have “example.org” configured as a virtual domain and “email@example.com” as a user in that domain.
Send a test email
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:
echo test | mail 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:
Nov 8 22:29:40 jessie postfix/pickup: D663322AF9: uid=0 from=<root> Nov 8 22:29:40 jessie postfix/cleanup: D663322AF9: message-id=<20151108222940.D663322AF9@debian-jessie.vagrantup.com> Nov 8 22:29:40 jessie postfix/qmgr: D663322AF9: from=<email@example.com>, size=313, nrcpt=1 (queue active) Nov 8 22:29:40 jessie dovecot: lmtp(26859): Connect from local Nov 8 22:29:40 jessie dovecot: lmtp(26859, firstname.lastname@example.org): 4xrmNdTMP1braAAACYsm4Q: sieve: msgid=<20151108222940.D663322AF9@debian-jessie.vagrantup.com>: stored mail into mailbox 'INBOX' Nov 8 22:29:40 jessie postfix/lmtp: D663322AF9: to=<email@example.com>, relay=debian-jessie.vagrantup.com[private/dovecot-lmtp], delay=0.06, delays=0.02/0/0.01/0.02, dsn=2.0.0, status=sent (250 2.0.0 <firstname.lastname@example.org> 4xrmNdTMP1braAAACYsm4Q Saved) Nov 8 22:29:40 jessie dovecot: lmtp(26859): Disconnect from local: Successful quit Nov 8 22:29:40 jessie postfix/qmgr: D663322AF9: removed
Your output will look slightly different. But 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 several directories and extra files:
/var/vmail/ /var/vmail/example.org /var/vmail/example.org/john /var/vmail/example.org/john/Maildir /var/vmail/example.org/john/Maildir/dovecot-uidvalidity /var/vmail/example.org/john/Maildir/dovecot.index.cache /var/vmail/example.org/john/Maildir/tmp /var/vmail/example.org/john/Maildir/dovecot.index.log /var/vmail/example.org/john/Maildir/cur /var/vmail/example.org/john/Maildir/dovecot-uidvalidity.562762ef /var/vmail/example.org/john/Maildir/dovecot-uidlist /var/vmail/example.org/john/Maildir/new /var/vmail/example.org/john/Maildir/new/1445423017.M410998P32117.ispmail-jessie,S=376,W=386
Your files may have slightly different numbers. That’s okay. The line printed in bold letter depicts the actual email file. It is the only file in the “new” folder.
Access the email as a file
So John finally has finally received a new email into his inbox (that I have highlighted in bold letters). Just open that file and take a look – it is just a standard email with headers and a body. On my system it reads:
Return-Path: <email@example.com> Delivered-To: firstname.lastname@example.org Received: by ispmail-jessie.pmd.local (Postfix, from userid 0) id 54FF0260EB4; Wed, 21 Oct 2015 12:23:37 +0200 (CEST) To: email@example.com Message-Id: <20151021102337.54FF0260EB4@ispmail-jessie.pmd.local> Date: Wed, 21 Oct 2015 12:23:37 +0200 (CEST) From: firstname.lastname@example.org (root)test
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.
Access the email from your disk using mutt
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:
Press enter and you can read the email number 1:
So there is your test email. Press “q” to quit “mutt”.
This is a simple method to access mail directories on disk to trace problems.
Access the email through IMAP using mutt
Actually we just cheated a little as we have accessed John’s inbox directly on disk. A better test is to use POP3 or IMAP. And fortunately “mutt” supports IMAP:
mutt -f imap://email@example.com@localhost
You may be prompted to confirm that you are connecting to a mail server with an untrusted SSL certificate. That’s okay if you generated a self-signed certificate. In the end you should see the index and email just like in the screenshots above. (The password is “summersun” – remember?) That worked? Great. Otherwise check your /var/log/mail.log for error messages.
The parameter after the “-f” looks a bit weird, doesn’t it. Let me explain it:
The protocol. You can also use “imaps” but mutt automatically switches to imaps here.
The login name (as we use the email address as the user name, too)
The seperator between the user name and the host name of the mail server
The mail server
Access the email through IMAP using a desktop mail 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 (or “icedove” on Debian) then feel free to configure a new email account using IMAP and connect to the server. Remember that the user name and email address are both “firstname.lastname@example.org” and the password is “summersun”.
Access the email through Roundcube webmail
And last but not least you have a very easy way to access John’s emails by just using your web browser. After all you installed Roundcube earlier. So go to https://YOUR.MAIL.SERVER/ and login as “email@example.com” with password “summersun”. That should take you to the inbox:
POP3 versus IMAP
If you wonder what the difference between POP3 and IMAP is:
- 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).