How to install and configure Postfix, Dovecot and SquirrelMail on Debian Linux

Valic —  November 13, 2012 — 8 Comments

If you want to set-up an mail server in Debian Linux using Postfix and SquirrelMail you need to follow the next guide:

Step1.  Install Postfix:

apt-get install postfix

This command will remove sendmail. Sendmail is installed by default on Debian.

Step2. Configure Postfix:

Open the file /etc/postfix/main.cf with your favorite editor and uncomment or add the followins:

inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/

Step3. Restart and test if Postfix is working:

/etc/init.d/postfix restart

To test Postfix follow the next steps:

telnet localhost 25

You should receive the follwing response:

Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
220 test ESMTP Postfix (Debian/GNU)

MAIL FROM:

You will get this output:

250 2.1.0 Ok

Now add receiver:

RCPT TO:

Note that you should have this user on system if you want to check mail later.You will receive another 250 OK message.

To start the main body of the message use this:

DATA

The server response will be:

354 End data with.

Now you need to enter the subject and the mesage body.

Subject: test mail

Press enter and then you can type the body of the email.

This is a test mail

Make sure that you end the body of the email with (.)to indicate you have finished the body of the email.
Ther server response will be something like this:

250 2.0.0 Ok: queued as 09F02358036

Now type QUIT.

Now chek if you have mail:

tail -n 15 /var/mail/demo

The Output will look like this:

From test@debian-tutorials.com Tue Nov 13 18:48:25 2012
Return-Path:
X-Original-To: demo@debian-tutorials.com
Delivered-To: demo@debian-tutorails.com
Received: from localhost (localhost [127.0.0.1])
by test (Postfix) with SMTP id 09F02358036
for ; Tue, 13 Nov 2012 18:41:22 +0200 (EET)
Subject: test message
Message-Id:
Date: Tue, 13 Nov 2012 18:41:22 +0200 (EET)
From: test@debian-tutorials.com

This is a test mail.

Now you are sure that Postfix is working

Step4. Install and configure Dovecot POP3/IMAP Server

apt-get install dovecot-common dovecot-pop3d dovecot-imapd

To configure Dovecot edit the configuration file  /etc/dovecot/dovecot.conf

Add or uncomment the following lines:

protocols = imap imaps pop3 pop3s
mail_location = maildir:~/Maildir
imap_client_workarounds = delay-newmail outlook-idle netscape-eoh
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh

Step5. Restart and test Dovecot

/etc/init.d/dovecot restart

telnet localhost pop3
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
+OK Dovecot ready.
user test
+OK
pass testpassword
+OK Logged in.
list
+OK 0 messages:

As we see, the Dovecot is working.

Step6. Configure Dovecot SASL and Postfix SMTP Auth.

Open the file /etc/dovecot/dovecot.conf and edit as follows:

auth default {
socket listen {
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
mechanisms = plain login
}

Now open the /etc/postfix/main.cf file and make the following changes:

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes

Step7. Restart Postfix and Dovecot

/etc/init.d/postfix restart
/etc/init.d/dovecot restart

Step8. Install SquirrelMail Webmail

apt-get install squirrelmail squirrelmail-compatibility php-pear php-db

Step9. How to Configure SquirrelMail Webmail

Step9.1 Symlink the SquirrelMail virtualhost to the /etc/apache2/conf.d directory and restart Apache2:

ln -s /etc/squirrelmail/apache.conf /etc/apache2/conf.d/squirrelmail.conf
/etc/init.d/apache2 restart

Step 9.2 Use the following command to start the SquirrelMail Configuration utility.

squirrelmail-configure

You will see the following menu. Navigate as follows:

SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Main Menu –
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color on
S Save data
Q Quit

Command >> Type D

SquirrelMail Configuration : Read: config.php
———————————————————
While we have been building SquirrelMail, we have discovered some
preferences that work better with some servers that don’t work so
well with others. If you select your IMAP server, this option will
set some pre-defined settings for that server.

Please note that you will still need to go through and make sure
everything is correct. This does not change everything. There are
only a few settings that this will change.

Please select your IMAP server:
bincimap = Binc IMAP server
courier = Courier IMAP server
cyrus = Cyrus IMAP server
dovecot = Dovecot Secure IMAP server
exchange = Microsoft Exchange IMAP server
hmailserver = hMailServer
macosx = Mac OS X Mailserver
mercury32 = Mercury/32
uw = University of Washington’s IMAP server
gmail = IMAP access to Google mail (Gmail) accounts

quit = Do not change anything
Command >> Type dovecot

imap_server_type = dovecot
default_folder_prefix = INBOX.
trash_folder = Trash
sent_folder = Sent
draft_folder = Drafts
show_prefix_option = false
default_sub_of_inbox = false
show_contain_subfolders_option = false
optional_delimiter = .
delete_folder = true

Press enter to continue… press ENTER

SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Main Menu –
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages

D. Set pre-defined settings for specific IMAP servers

C Turn color on
S Save data
Q Quit

Command >> Type 8

SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Plugins
Installed Plugins
1. view_as_html

Available Plugins:
2. administrator
3. bug_report
4. calendar
5. change_sqlpass
6. compatibility
7. delete_move_next
8. demo
9. filters
10. fortune
11. info
12. listcommands
13. mail_fetch
14. message_details
15. newmail
16. sent_subfolders
17. spamcop
18. squirrelspell
19. test
20. translate

R Return to Main Menu
C Turn color on
S Save data
Q Quit

Command >> Activate how many plugins do you want.

SquirrelMail Configuration : Read: config.php (1.4.0)
———————————————————
Plugins
Installed Plugins
1. view_as_html

Available Plugins:
4. administrator
5. bug_report
6. calendar
7. delete_move_next
8. demo
9. filters
10. fortune
11. info
12. listcommands
13. mail_fetch
14. message_details
15. newmail
16. sent_subfolders
17. spamcop
18. squirrelspell
19. test
20. translate

R Return to Main Menu
C Turn color on
S Save data
Q Quit

Command >> Type S to Save Data and them Q

Now you can login to squirrelmail

htto://yourdomain.tld/squirrelmail

Enjoy.

Valic

Posts Twitter Facebook

Editor in Chief at Debian-Tutorials, Linux enthusiast.

8 responses to How to install and configure Postfix, Dovecot and SquirrelMail on Debian Linux

  1. Great tutorial,

    Thank’s

  2. nice work !
    but i have many errors on dovecot restart ! but it works ;)

  3. Can you tell me what kind of error do you have?

  4. just one question, doing this on my server will I be able to sent mails to others? like gmail, hotmail accounts

  5. at the beginning when I install postfix and modify the file i get error with the command telnet localhost 25:
    Trying 127.0.0.1…
    Connected to localhost.
    Escape character is ‘^]’.
    220 localhost ESMTP Postfix (Debian/GNU)
    421 4.4.2 localhost Error: timeout exceeded
    Connection closed by foreign host.

    what can i do to fix it?

  6. is postfix running?

  7. Hey Valic, I got it. IT was a location variable that was causing an issue in dovecot.con. As I am still using mbox, I had to change it to; mail_location = mbox:~/mail:INBOX=/var/mail/%u.

    Thank you very much for the above instructions! Best regards from Poland!

Leave a Reply