Raspberry Pi Email Server Part 2: Dovecot

Dovecot Logo

This is the second part of a five part tutorial that will show you how to install a full featured email server on your Raspberry Pi. This tutorial covers Dovecot, which provides SASL authentication and IMAP capabilities. The parts are:

The Introduction & Contents Page (read first)
Raspberry Pi Email Server Part 1: Postfix
Raspberry Pi Email Server Part 2: Dovecot
Raspberry Pi Email Server Part 3: Squirrelmail
Raspberry Pi Email Server Part 4: Spam Detection with Spamassassin
Raspberry Pi Email Server Part 5: Spam Sorting with LMTP & Sieve

Fixing the errors that appeared during dovecot installation

In part 1, when you installed Dovecot I mentioned that you might see some errors like this:

Creating config file /etc/dovecot/conf.d/20-imap.conf with new version
[....] Restarting IMAP/POP3 mail server: dovecotError: socket() failed: Address family not supported by protocol
Error: service(imap-login): listen(::, 143) failed: Address family not supported by protocol
Error: socket() failed: Address family not supported by protocol
Error: service(imap-login): listen(::, 993) failed: Address family not supported by protocol
Fatal: Failed to start listeners
invoke-rc.d: initscript dovecot, action "restart" failed.
dpkg: error processing dovecot-imapd (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up dovecot-ldap (1:2.1.7-7) ...

These errors are caused by the lack of IPv6 support, which I mentioned in the previous tutorial. To remove the errors, open the main dovecot configuration file (/etc/dovecot/dovecot.conf) and find this line:

listen = *, ::

And change it to:

listen = *

The * means “all IPv4 addresses”, the :: means “all IPv6 addresses”. Now restart Dovecot, and you shouldn’t get any errors:

sudo service dovecot restart

Note: since I wrote this tutorial, there have been a few small changes to the default configuration file - you may find that the line is commented (with a # at the start of the line). If so, remember to uncomment it when you make your changes!

Tell Dovecot where your Mailbox is

Open /etc/dovecot/conf.d/10-mail.conf and find this line:

mail_location = mbox:~/mail:INBOX=/var/mail/%u

Change it to this:

mail_location = maildir:~/Maildir

Instruct Postfix to use Dovecot SASL

Now we need to tell Postfix that we would like to use Dovecot for SASL authentication. Open /etc/postfix/main.cf and add these lines:

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes

Now tell Dovecot to listen for SASL authentication requests from Postfix. Open /etc/dovecot/conf.d/10-master.conf and comment out the current block that begins with service auth (place a # at the start of each line). Replace it with this:

service auth {
        unix_listener /var/spool/postfix/private/auth {
                mode = 0660
                user = postfix
                group = postfix

Now you want to enable plain text logins. Do it by adding these two lines to /etc/dovecot/conf.d/10-auth.conf. Make sure they are not already present in the file, or your settings may be overwritten with the default ones if the default is declared later in the file than the lines you add. If the parameters are already present, you can either modify the existing lines or comment them out and add these new ones:

disable_plaintext_auth = no
auth_mechanisms = plain login

Note that although the logins are in plain text, we will be setting Postfix up later so that it only allows you to use plaintext logins from within SSL/TLS. This means that your login and password will sent in an encrypted session - you wouldn't see them in plain text if you used a packet sniffer, for example. For now, we’re allowing unencrypted plain text logins so that we can test logging in with Telnet. Since the connection is local (from the Pi to the Pi), your password isn’t being sent over any insecure networks so this is fine.

Testing SASL

Creating a new user for testing purposes is a good idea. Let’s call this temporary user testmail and give it the password test1234 Use this command to add the user, and follow the prompts including setting a password.

sudo adduser testmail

Now restart Postfix and Dovecot:

sudo service postfix restart
sudo service dovecot restart

We’re now going to try and send an email after authenticating with SASL. The server is expecting to see a base64 encoded version of your username and password, so we have to convert it first. There are three ways of doing this, so I've given examples below using the testmail username and test1234 password:

#Method No.1
echo -ne '\000testmail\000test1234' | openssl base64

#Method No.2
perl -MMIME::Base64 -e 'print encode_base64("\0testmail\0test1234");'

#Method No.3
printf '\0%s\0%s' 'testmail' 'test1234' | openssl base64

I have discovered that if your password starts with a number, methods 1 and 2 don’t work. Assuming the username and password are testmail and test1234, the commands produce this:


WARNING: If you’re having problems with authentication and you paste examples to forums or mailing lists, be aware that it is really easy to convert this back into your username and password (hence the creation of a test user). If you're using your real username and password to test, redact it before posting!

Now, still logged into the Pi via SSH, you can telnet port 25 to test whether or not SASL is working. There’s only one extra step, which is the AUTH PLAIN command that comes after ehlo but before mail from. For testing, the permit_mynetworks parameter should be commented out under your postfix smtpd_recipient_restrictions block in /etc/postfix/main.cf. If you’re following on from Raspberry Pi Email Server Part 1: Postfix then this should already be the case. If you have to change it, remember to reload postfix (sudo service postfix reload) after you change the value. Here’s an example:

telnet localhost 25
Connected to localhost.
Escape character is '^]'.
220 samhobbs ESMTP Postfix (Debian/GNU)
ehlo facebook.com
250-SIZE 10240000
250 DSN
235 2.7.0 Authentication successful
mail from:testmail
250 2.1.0 Ok
rcpt to:me@externalemail.com
250 2.1.5 Ok
354 End data with .
Subject: This is my first email that has been authenticated with Dovecot SASL
Woop woop
250 2.0.0 Ok: queued as B87133F768
221 2.0.0 Bye
Connection closed by foreign host.

Now try again but enter the username/password incorrectly (base64 encode something random) – you should get an error message and the email won’t send. If everything went to plan, then SASL is working properly!

You can now uncomment permit_mynetworks again.

Separating Incoming email (unauthenticated) from Outgoing Email (SASL authenticated)

It’s probably a good idea to have a dedicated port for sending outgoing email…here’s why: Port 25 doesn’t require (but does offer) SSL/TLS encryption. If you mess up configuring your mail client you could end up letting it authenticate with SASL over insecure connections. Using a different port that only accepts SSL/TLS connections removes the risk that a poorly configured email client could be sending your password unencrypted over dodgy networks. There are two ports you can use for this:

  1. 465: SMTP over SSL
  2. 587: Email submission

587 is the “official” port for email clients (like K9 mail, Thunderbird and Outlook) to use when submitting messages to the Mail Submission Agent (your email server) – the submission may be encrypted or unencrypted depending on the server configuration. 465 was a port that was assigned for SMTP with SSL/TLS before the STARTTLS protocol was introduced, back in the days when you chose your port and that decided on the type of connection you were going to get (encrypted or unencrypted).

STARTTLS changed things because it allows you to connect with an unencrypted connection (like the one you get with Telnet), and then upgrade to an encrypted connection without changing port… so when STARTTLS was introduced, SMTPS on port 465 was removed from the standard because you could do the same thing with a single port (25).

However, I think there is some value in specifying a port for submission that only accepts SSL/TLS encrypted connections, and won’t work if the connection isn’t encrypted. This means that if you misconfigure your email client it just won’t work, instead of working and sending your password in an unencrypted format. So, anyway… Here’s how to set up Postfix to listen on port 465 for encrypted connections. The first step is telling Postfix to listen on port 465, so open /etc/postfix/master.cf and uncomment the line:

smtps     inet  n       -       -       -       -       smtpd

Now restart Postfix:

sudo service postfix restart

Test whether Postfix is listening on port 465:

telnet localhost 465
Connected to localhost.                                                                       
Escape character is '^]'.
220 samhobbs.co.uk ESMTP Postfix (Debian/GNU)
ehlo samhobbs.co.uk
250-SIZE 10240000
250 DSN
221 2.0.0 Bye
Connection closed by foreign host.

OK, so now it’s listening on the right port, but it’s allowing unencrypted connections. Here’s how you force TLS on port 465: open /etc/postfix/master.cf and find the line you uncommented earlier. Below it are some options, you want to edit them so that they look like this (i.e. uncomment lines 2 and 3):

smtps     inet  n       -       -       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes

Line 3 is forcing TLS on port 465, and line 2 means that connections to port 465 have a different label in the logs, which can be useful for debugging.

sudo service postfix restart

Now try connecting with Telnet again… you should be able to establish a connection, but not receive any prompts from the server:

telnet localhost 465                                            
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

Now try openssl:

openssl s_client -connect localhost:465 -quiet
depth=0 CN = samhobbs
verify error:num=18:self signed certificate
verify return:1
depth=0 CN = samhobbs
verify return:1
220 samhobbs.co.uk ESMTP Postfix (Debian/GNU)
221 2.0.0 Bye

Good: we are able to start a TLS encrypted connection. We got some errors because the certificate is self-signed (it's not signed by a certificate that is in the trusted root store on the server) but this is OK because we're just using the certificate for testing for now. When you come back later to set up a proper certificate, you can use this command to verify it. The -CApath option tells openssl where the trusted certificates are stored on your system:

openssl s_client -connect localhost:465 -quiet -CApath /etc/ssl/certs

Successful validation looks something like this:

sam@samhobbs:~$ openssl s_client -connect localhost:465 -quiet -CApath /etc/ssl/certs
depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root
verify return:1                                                                              
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify return:1                                                                              
depth=1 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Domain Validation Secure Server CA
verify return:1                                                                              
depth=0 OU = Domain Control Validated, OU = PositiveSSL, CN = samhobbs.co.uk                 
verify return:1                                                                              
220 samhobbs.co.uk ESMTP Postfix (Ubuntu)                                                    
221 2.0.0 Bye

There are a couple more changes we want to make here: first, tell Postfix to only advertise SASL authentication over encrypted connections (so that you don’t accidentally send your password in the clear). Open /etc/postfix/main.cf and add this line:

smtpd_tls_auth_only = yes
sudo service postfix reload

Now connect to port 25 and you shouldn’t see AUTH advertised:

telnet localhost 25
Connected to localhost.
Escape character is '^]'.
220 samhobbs.co.uk ESMTP Postfix (Debian/GNU)
ehlo samhobbs.co.uk
250-SIZE 10240000
250 DSN

Lastly, we want to override the smtp_recipient_restrictions for port 465 so that it doesn't accept incoming messages from unauthenticated users.

At first, I didn't make this change and I noticed that some spam emails were coming in on port 465 and bypassing my spam filter, which I configured to scan all incoming email on port 25, but not 465 because I only expected it to be used for outgoing email. We can do this by overriding the smtp_recipient_restrictions list for port 465 in /etc/postfix/master.cf. Open master.cf and find the smtps line. Add a new recipient restrictions list option like this:

smtps     inet  n       -       -       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject

Now reload postfix:

sudo service postfix reload

Perfect! Postfix configuration is now complete.

Testing IMAP

There are two main protocols for fetching mail: POP and IMAP. The main difference between them is what they do with emails when they collect them: a POP client will fetch email from your server and remove it from the server when it’s done. This is inconvenient if you want to connect with two or more devices (like a phone and a computer) and have complete copies of all your emails on both. IMAP, on the other hand, makes a copy of the emails on the server and leaves the originals there. For this reason, I think IMAP is much more useful than POP and I didn’t even bother to set up POP on my server. We can now test the IMAP server with Telnet in a similar way to SMTP & SASL testing earlier. This time, we’ll be using port 143, the standard port for IMAP. The stages are:

  1. establish a connection with telnet localhost 143
  2. log in with a login "USERNAME" "PASSWORD"" (not base64 encoded this time)
  3. select inbox to see messages inside b select inbox
  4. logout with c logout

In case you're wondering, the "a b c" thing is done because a client can send multiple commands to the server at once, and they might not come back in the same order depending on what they are. So, the responses have the same letter as the commands they are responding to so that the client doesn't get muddled.

Here’s an example, using the testmail user we created earlier:

telnet localhost 143
Connected to localhost.
Escape character is '^]'.
a login "testmail" "test1234"
b select inbox
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* OK [UNSEEN 1] First unseen.
* OK [UIDVALIDITY 1385217480] UIDs valid
* OK [UIDNEXT 2] Predicted next UID
* OK [NOMODSEQ] No permanent modsequences
b OK [READ-WRITE] Select completed.
c logout
* BYE Logging out
c OK Logout completed.
Connection closed by foreign host.

Adding TLS support

Now that we know IMAP is working, we need to enable IMAPS (imap with SSL/TLS). The standard port for this is 993.

Many other tutorials that were written for older versions of dovecot will tell you to do this in different ways that won’t work, I tried 3 different methods before I ended up with a working one.

First, edit /etc/dovecot/conf.d/10-master.conf, find the “service imap-login” block and uncomment the port and SSL lines so that it looks like this:

service imap-login {
  inet_listener imap {
    port = 143
  inet_listener imaps {
    port = 993
    ssl = yes

Edit 14/10/2015: the default dovecot configuration files changed recently after Jessie became the new stable distribution of Debian, which caused some users problems; TLS on port 993 used to be enabled by default but now it isn't. We need to re-enable it.

In /etc/dovecot/conf.d/10-ssl.conf, find ssl = no and change it to:

ssl = yes

There have been some security vulnerabilities discovered in older versions of the SSL protocol in recent times. SSLv2 is disabled by default, but it doesn't harm to explicitly disable it again. SSLv3 is vulnerable to an attack called POODLE, so we will disable it too. In the same file, find the ssl_protocols parameter line, uncomment it and add !SSLv3 to the end, like this:

ssl_protocols = !SSLv2 !SSLv3

Edit 02/09/2017: if you're using Debian Stretch or later, or one of its derivatives, then you will need to edit that line to match the following. The SSLv2 option is no longer recognised as an option for ssl_protocols because it has been removed entirely:

ssl_protocols = !SSLv3

For some bizarre reason, the Dovecot package for Raspberry Pi (and possibly newer versions of Ubuntu) does not create a self-signed certificate during installation like it used to. So, we have to create one manually. If you look in /usr/share/dovecot/ you will find the script that used to be used to generate the certificate; we can use it ourselves to simplify the process.

The script is located at /usr/share/dovecot/mkcert.sh and looks like this:


# Generates a self-signed certificate.
# Edit dovecot-openssl.cnf before running this.




if [ ! -d $CERTDIR ]; then
  echo "$SSLDIR/certs directory doesn't exist"
  exit 1

if [ ! -d $KEYDIR ]; then
  echo "$SSLDIR/private directory doesn't exist"
  exit 1

if [ -f $CERTFILE ]; then
  echo "$CERTFILE already exists, won't overwrite"
  exit 1

if [ -f $KEYFILE ]; then
  echo "$KEYFILE already exists, won't overwrite"
  exit 1

$OPENSSL req -new -x509 -nodes -config $OPENSSLCONFIG -out $CERTFILE -keyout $KEYFILE -days 365 || exit 2
chmod 0600 $KEYFILE
$OPENSSL x509 -subject -fingerprint -noout -in $CERTFILE || exit 2

If you were going to use this certificate for any significant length of time, it would be worth editing the parameters in the config file it uses (/usr/share/dovecot/dovecot-openssl.cnf) to set the proper common name and contact details on the certificate. However, I suggest you leave the defaults as they are, use this certificate just for testing, and then come back later and generate a new cert when everything is working (more on that later).

You must be in the same folder as the configuration file when you run the script, or it will not find the config and the certificate generation will fail. The following two commands will change to the right folder and then execute the script:

cd /usr/share/dovecot
sudo ./mkcert.sh

You should see a message "writing new private key to '/etc/dovecot/private/dovecot.pem'" and then some details about the certificate.

Next, find the following two lines in /etc/dovecot/conf.d/10-ssl.conf and uncomment them:

#ssl_cert = </etc/dovecot/dovecot.pem
#ssl_key = </etc/dovecot/private/dovecot.pem

Now reload dovecot to apply the changes:

sudo service dovecot reload

Since IMAPS is a connection over SSL/TLS, we can’t use Telnet to test it. Instead, we use openssl to create a secure connection. There are two versions of the command, one will show you LOADS of information about the certificate used to encrypt the connection, and the other will suppress this info. I recommend trying the long version out of interest, but both will work the same for the test:

For full information:

openssl s_client -connect localhost:993

For minimal information:

openssl s_client -connect localhost:993 -quiet

I won’t print the output of the first command, because it’s ridiculously long. Here’s an example of the second, including a login test:

admin@samhobbs /etc/dovecot/conf.d $ openssl s_client -connect localhost:993 -quiet
depth=0 O = Dovecot mail server, OU = samhobbs, CN = samhobbs, emailAddress = root@samhobbs.co.uk
verify error:num=18:self signed certificate
verify return:1
depth=0 O = Dovecot mail server, OU = samhobbs, CN = samhobbs, emailAddress = root@samhobbs.co.uk
verify return:1
a login "testmail" "test1234"
b logout
* BYE Logging out
b OK Logout completed.
Connection closed by foreign host.

Good stuff: SSL/TLS is working on port 993, and you can log in successfully.

Note that by default Dovecot uses a “snakeoil” self-signed certificate. SSL/TLS certificates are used for two purposes: encryption and verification. The “snakeoil” certificate will encrypt your content but it won’t verify that you’re talking to your server – you could be talking to someone imitating your server (anyone can create a self-signed certificate claiming to be any website).

If you’d like to get your certificate signed without forking out loads of money to a cert signing authority, I’d recommend CAcert. I've written a tutorial explaining how to generate your own cert and get it signed here. If you opt for a commercial certificate, you can use the CAcert tutorial to generate the certificate and then this tutorial will explain the differences in the installation/configuration of commercial certificates once you have it signed.

If you're testing a proper certificate, use this command to tell openssl where the trusted root certificates are stored:

openssl s_client -connect localhost:993 -quiet -CApath /etc/ssl/certs

Tidying up and enabling WAN access

Before opening the ports on your router to the world, it’s a good idea to delete that test user because the password is so easy to guess.

sudo userdel testmail

Also, if you still use the "pi" login, for goodness' sake change the password from "raspberry"! You can do this using the passwd command when logged in as pi:


Or you can achieve the same thing when logged in as another user by using sudo to gain root privileges:

sudo passwd pi

Now you can open a few ports on your router’s firewall. Make sure your Pi has a static LAN IP address and then forward these ports from WAN to its LAN IP address:

  • Port 25 for SMTP (used for receiving emails)
  • Port 465 for secure SMTP (used for sending emails after SASL authentication)
  • Port 993 for IMAPS (used to receive emails on your phone/tablet/computer)

Here’s an example on my router, running OpenWrt:


Setting up IMAP Email Clients

I’m now going to run through setting up IMAP email clients quickly, using K9 Mail on Android and Thunderbird on GNU/Linux as examples. The setup for Thunderbird on Windows and Mac OSX should be very similar.

The basics are this:

  • Select an IMAP connection
  • Your login is your username only (omit @yourdomain.com), and you password is…your password!
  • For incoming emails: select use SSL/TLS always and the program should automatically select port 993
  • For outgoing emails: select SSL/TLS always. The program may suggest port 587, but you want port 465

K9 Mail

Open K9 Mail and select add new account. Type in your account information (you@yourdomain.com and password) and then select manual setup. Select IMAP and then enter your information as follows…

Incoming email:

K9 Incoming Email Settings

Outgoing email:

K9 Outgoing Email Settings


Open Thunderbird, and then click Account Actions –> Add Mail Account.

Fill in your password and email address, which is your username followed by your fully qualified domain name (FQDN), i.e. username@yourdomain.com:

Thunderbird Step 1: Mail Account Setup

Thunderbird will try to auto-detect settings and fail. Don’t worry, this is normal. Select “manual config”:

 Thunderbird Step 2: TB will try to autodetect settings, and fail. Select “Manual Config"

Now edit the settings as appropriate. I had to remove a period (.) from in front of my “server hostname”, and edit the SSL and Authentication settings. If you select “SSL/TLS” for both incoming and outgoing, ports 993 and 465 are automatically selected:

Thunderbird Step 3: Edit the settings so that they match these (but change them to match your username and domain name!)

Now try emailing yourself from your external email address, and see if your email gets through. If you are having problems, be sure to check you’ve set up an MX record as well as a DNS A record.

Stuck in spam filters?

A few people have contacted me recently to say that their email server is working fine but their emails are getting sent to Gmail's spam folder.

If you are experiencing problems like this (or even if you're not), try setting up an SPF and/or PTR record as explained in my DNS basics tutorial.

You might also want to check if your domain name or IP address are on any blacklists. There's a handy website called MX toolbox that lets you do this (choose blacklist check from the dropdown menu).

Almost done…

Good news! If you’ve reached this far and everything is working, then you’re almost done. The next step (Webmail with Squirrelmail) is optional but by far the easiest of the three steps.

If you’ve hit a rut, please post a comment and I’ll try and help you out.

If not… continue to Raspberry Pi Email Server Part 3: Squirrelmail



Honestly I'm not sure what that means, I've not experimented with traceroute much before.

Try emailing me to make sure it's not something specific to those domains, my email address is on the get in touch page.

Someone recently had a very similar problem by the way, I couldn't work out what it was... :/ weird networking problem!

There is the complete log :
Aug 17 18:21:52 localhost postfix/smtps/smtpd[2697]: connect from unknown[]
Aug 17 18:21:59 localhost postfix/smtps/smtpd[2697]: 0FA4262B8: client=unknown[], sasl_method=LOGIN, sasl_username=otyugh
Aug 17 18:21:59 localhost postfix/cleanup[2705]: 0FA4262B8: message-id=<20140817202150.55ce5026@otyugh.pwnzz.org>
Aug 17 18:22:00 localhost postfix/qmgr[1921]: 0FA4262B8: from=, size=545, nrcpt=1 (queue active)
Aug 17 18:22:00 localhost postfix/smtps/smtpd[2697]: disconnect from unknown[]
Aug 17 18:22:30 localhost postfix/smtp[2686]: connect to samhobbs.co.uk[]:25: Connection timed out
Aug 17 18:22:32 localhost postfix/smtp[2686]: 0FA4262B8: to=, relay=none, delay=32, delays=1.5/0/30/0, dsn=4.4.1, status=deferred (connect to samhobbs.co.uk[]:25: Connection timed out)

(I changed my true mail to avoid spam. Added a z to pwnz.
Also, here I'm connecting to my server from my desktop
If you see anything wrong. If not I'll just search further and repport if I find any answer. I'll maybe phone my ISP.)
Thanks again.

telnet samhobbs.co.uk 25
Unable to connect to remote host: Connection timed out

I think you made you point. I'll phone the ISP and ask why it is refusing the freedom to his user to get their own mailsevers.

I guess I'll have to point to another smtp server to get my mail working as you suggested.
The ISP I'm with is called Orange (or france telecome) -yes I'm in France-. It's mainstream but has an overall bad reputation as "respecting his users".
There is very few ISP considered as okay in france : they are or citizen initiative (like FDN) or professionnal solutions.

after logging in via telnet 143 and b select inbox i get the follwoing:

b select inbox
b NO [SERVERBUG] Internal error occurred. Refer to server log for more information. [2014-08-18 12:34:23]

At a guess, either your Maildir wasn't created properly (doesn't exist or has the wrong permissions) or Dovecot thinks your mailbox is somewhere else.

Could you run these commands and paste the output please (assuming you are logged in as the user you are testing for mail).

ls -al ~
ls -al ~/Maildir

And check that this line is correct in /etc/dovecot/conf.d/10-mail.conf:

mail_location = maildir:~/Maildir


I've tried many other tutorials for Postfix+Dovecot and this is the only one that was well explained, fully documented, and worked like a charm. Many thanks.

Many thanks for your work. I was going through the postfix and dovecot tutorials and everything works fine now :-).

First I had trouble with Apple's Mail.app and the connection to port 465. The reason was, that dovecot use another SSL certificate than postfix by default, and Mail.app didn't accept that.

I ran sudo service dovecot restart

The following appeared:
doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/10-master.conf line 93: Unexpected '}'
[....] Restarting IMAP/POP3 mail server: dovecotdoveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/10-master.conf line 93: Unexpected '}'

Please help!

As the error message says, you have a } in the wrong place in /etc/dovecot/conf.d/10-master.conf, on line 93... remove it and restart dovecot!

Hi Sam,

First of all, great job for this excellent tutorial!

I have been through it and have succeeded in having my mail server working (sending and receiving).
One remark however: I can't manage to have the sent mails copied/moved to the "Sent" directory. They are actually properly sent as I can receive them on my gmail account, but nothing appears in the "Sent" directory.
Who is suppose to be taking care of this, Postfix or Dovecot?
I have been googling these last hours on this but no clue...

Hi Sam,

Thanks for your answer.
Based on your comment above (it is the client job to do this, not the server job) I googled a bit and find the solution (I am using Kmail). So problem solved.

For those having the same issue using Kmail, go to Configuration -> Config Kmail -> Identities.
By modifying the identities, it is possible to tell Kmail what to do with the sent messages, drafts etc.

I use kmail too, and was stumped by that at first, it's different to other clients!

Glad you figured it out, thanks for posting!


Seem to have everything working up to the Testing SASL point.
I restart Postfix and Dovecot, no errors, all looks good. Then I telnet in and get as far as AUTH PLAIN AHRl...
The system returns "503 5.5.1 Error: authentication not enabled"
It seems I must have missed something, but can't tell what it is. I have been back over all the dovecot steps 3 times now.
Any ideas?

Hi Sam,
Don't worry about my last message, it was a spelling mistake in the postfix config file, I had smpt instead of smptd in the enable sasl line.
Let's see how far I can get through this without snags. So far I've had a few, including not being able to find the "\" character because the keyboard settings pointed to a gb keyboard and here in Australia we have US keyboards.

Sam, the RaspberryPi now receives emails. I am using pi@georgegalanis.homeip.net. I can send emails to it from my main computer (and from my blackberry etc outside of the LAN) and I can see the emails arriving at the server in the /home/pi/Maildir/new folder. I don't have Thunderbird, so I am trying to create a new account in Outlook. I am setting up the Incoming mail server as imap.georgegalanis.homeip.net and the outgoing mail server as smtp.georgegalanis.homeip.net. User name as pi@georgegalanis.homeip.net. I have the incoming server port as 993 and outgoing server as port 25, all consistent with my port forwarding settings. When I have configured all that outlook tries test the settings by loggin onto the IMAP server and sending a test message. Nothing happens for a number of minutes and then it returns with 2 errors: "Log onto incoming mail Server (IMAP): Your server unexpectedly terminated the connection. Possible causes include server problems, network problems, or a long period of inactivity"; "Send test e-mail message: None of the authentification methods supported by this client are supported by your server." I suppose outlook is finding the server, but something is not set quite right. Any ideas? George

It seems Outlook has TLS/SSL option set to 'none' by default. So I set them both to 'Auto' The 'log onto incoming server' still fails. However the 'Send test e-mail message' now works. Any ideas why I can SMTP but not log onto the IMAP?

Got it, I was using port 993 (IMAPS) instead of port 143 (IMAP). Now I have my pi@georgegalanis.homeip.net emails in Outlook. (Wow and it only took 2 and a half days).
One question though. I want to set this up so that I get these emails on my mobile devices. However, when I set this up in outlook it came up with Certificat issues. So I accepted the certificate, but I have no idea what that was and I am wondering if this will create an issue for setting up accounts on my mobile devices?

George, you actually want to use port 993 for IMAPS so that it will only work with an encrypted connection, otherwise you might end up sending your password in plain text over the internet.

The ports that you should be forwarding on your router are 25 for incoming SMTP, 465 for submitting outgoing emails over SSL, and 993 for secure IMAP.

The certificate is what's used to verify that your server is who it says it is, and encrypt your session when you send authentication details etc.

By default your server uses a "snakeoil" self-signed certificate until you tell it to use a different one. The snakeoil cert does encrypt your session but it doesn't verify that you're taking to your server - it could be someone else impersonating it. Have a look at my CACert tutorial for how to get a certificate signed and installed.


Sam, not sure I understand this. I have the port forwarding on my router set up as you recommend. That is, SMTP 25, IMAP 143, SSMTP 465, IMAPS 993. Now from the client side I am using Outlook. To access my email server from outlook I have set Incoming Server (IMAP) 143, Outgoing SMTP 25, Outgoing server (SMTP) requires authentification and same settings for incoming mail. In the Server info I have imap.xxxx.net, smtp.xxxx,net User name is pi (user on my Raspberry pi), and I have checked the box saying 'require logon using Secure Password Authentication'. This configuration works. I have tried a number of others but no joy. So if what I have set up is not secure, then which fields do I change in Outlook???


The tutorial doesn't say you need to forward IMAP from WAN to LAN because you're not actually using it when you connect to the server with your email client - you're using IMAPS/993.

IMAP/143 is only set up on the server because it will be used by Squirrelmail to read your emails: since Squirrelmail will be running on the same machine you don't need to use SSL to encrypt the communication between it and Dovecot - the communication isn't being sent over any untrusted networks. IMAP does not need to be accessible from the internet, and it's best to disable the port forward so that you don't accidentally configure your email client to use IMAP and send your password unencrypted.

I'll also reply to your other comments, give me a minute :)


I just read through your instructions again and reran the tests. I get down to your test: openssl s_client -connect localhost:465 -quiet
The response seems fine, but the line 220 comes up as "220 raspberrypi ESMTP Postfix (Debian/GNU)" . I am wondering if where I am getting 'raspberrypi' I should be getting the name of the mail server. Should I be getting "220 georgegalanis.homeip.net ESMTP Postfix (Debian/GNU)" instead?

Ok, found the step that I got wrong earlier, which was myhostname set incorrenctly in postfix/main.cf, so I have fixed that and the telnet to port 465 now works correctly. I then go to Outlook and amend the Outgoing server (SMTP) from 25 to 465 and changed the "Auto' to force SSL and it works now. (It seems the Auto option in Outlook doesn't recognize what's actually set). Did the same thing for the IMAP server and it is now using port 993 now, so hopefully I have recreated what you are suggesting, so off to the next step and setting up squirrel. Just a question, when I set up my mobile devices they did not ask me for any ports, so what will they be using? Do I have to delete the email accounts on the mobile devices and recreate them?

Sounds like you sorted that one, congrats.

As for mobile devices, you'll need to be a bit more specific to get a meaningful answer! Which operating system are you using? Android / iOS / WebOS / Maemo / Blackberry / Sailfish ...?

The tutorial actually includes instructions for setting up K9 Mail, which is in my opinion the best email client for Android. Any good email client on any of the other operating systems should present you with similar options. Obviously you have to use a generic email client (not something like Gmail, which won't have an option for you to use your own server!).

If they didn't ask you for ports specifically, then they probably gave you options like "SSL - always", and I expect you just left them all at their default values/ "auto". You should be able to change the connection settings for existing accounts though, look carefully through the settings...

If I were you the first thing I would just disable that port forward for IMAP/143 and see what breaks. If you no longer receive emails on the mobile then you probably had it misconfigured to use IMAP without SSL.


Thanks Sam, I'll get back to you about the other issues. Right now I'm stuck on squirrelmail (of course). The command 'alias /squirrelmail /usr/share/squirrelmail doesn't work. In addition when I reload apache2 it seems to run apache, but there is a message "could not reliably determine the server's fully qualified domain name, using fir ServerName". I have set the hosts file and I do see the default web-page from my browser on the lan. Any ideas?

Alias /squirrrelmail /usr/share/squirrelmail

Is not a command, it's a line in squirrelmail's Apache config file. I think someone else asked this in the comments too.

The servername thing is not related to squirrelmail really. You can set the server name by setting ServerName foobar.com in your Apache configuration file. Not doing this doesn't break anything.


Thanks, I figured our that alias goes into the /etc/squirrelmail/apache.conf file just before I got your message. Once I figure that out I was able to bring up Squirrel on my main computer and I can run it as a local host. When I tried to add the https code I ended up getting a "Syntax error on Line 43 of /etc/apache2/sites-enabled/default-ssl" when I tried to restart Apache. I tried to back the changes out and couldn't seem to shake that error for a while, but finally got rid of it. So now I can send and receive emails from Squirrel as a local host. I cant seem to get your code for the https to work. Sorry, but your instructions are not clear. Can you tell me which file exactly I am supposed to enter that code into, and why do I get an error in some other file after I enter the code? (Squirrel is not the easy bit, this is the bit I have the most difficulty following)


Add new comment