How to Install Postfix with Roundcube Webmail on Ubuntu and Debian

Creating a mail server on Linux-powered machines can be one of the most essential tasks that every system administrator needs to perform while configuring the servers for the first time.

If you’re unfamiliar with what it entails, it’s quite simple. For example, if you have a website like “example.com“, you can create an email account such as “[email protected]“, this enables you to send and receive emails easily without relying on services like Hotmail, Gmail, Yahoo Mail, etc.

In this article, we’ll learn how to do so by installing the Postfix mail server with the “Roundcube” webmail application and its dependencies on Debian and Ubuntu distribution.

Step 1: Set a Hostname and DNS Records for Domain

1. First, set a valid FQDN (Fully Qualified Domain Name) hostname for your Ubuntu server using the hostnamectl command as shown.

sudo hostnamectl set-hostname mail.tecmint.com

2. Next, you need to add a MX and A records for your domain in your DNS control panel that guides other MTAs that your mail server mail.yourdomain.com domain is responsible for email delivery.

MX record    @           mail.tecmint.com
mail.tecmint.com        <IP-address>

Step 2: Installing Apache, MariaDB, and PHP on Ubuntu

3. To create a running mail server using “Roundcube”, we’ll have to install Apache2, MariaDB, and PHP packages first, to do so, run.

sudo apt update -y
sudo apt upgrade -y
sudo apt install apache2 apache2-utils mariadb-server mariadb-client php libapache2-mod-php php-mysql php-net-ldap2 php-net-ldap3 php-imagick php-common php-gd php-imap php-json php-curl php-zip php-xml php-mbstring php-bz2 php-intl php-gmp php-net-smtp php-mail-mime mailutils
Installing Apache, MariaDB, and PHP on Ubuntu
Installing Apache, MariaDB, and PHP on Ubuntu

Step 3: Installing Postfix Mail Server on Ubuntu

4. Postfix is a mail transfer agent (MTA) which is the responsible software for delivering & receiving emails, it’s essential in order to create a complete mail server.

To install it on Ubuntu/Debian or even Mint, run:

sudo apt install postfix
Install Postfix Mail Server
Install Postfix Mail Server

During installation, you will be asked to choose the type of mail configuration, and choose “Internet Site”.

Install Postfix in Ubuntu
Install Postfix in Ubuntu

5. Now enter the fully qualified domain name that you want to use for sending and receiving emails.

Set Postfix Mail Domain
Set Postfix Mail Domain

6. Once Postfix is installed, it will automatically start and create a new /etc/postfix/main.cf file. You can verify the Postfix status of the service using the following commands.

sudo systemctl status postfix
Check Postfix Status
Check Postfix Status

Step 4: Testing Postfix Mail Server on Ubuntu

7. Now try to check your mail server is connecting on port 25 using the following command.

$ telnet gmail-smtp-in.l.google.com 25

Trying 74.125.200.27...
Connected to gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP k12si849250plk.430 - gsmtp

The above message indicates that the connection is successfully established. Type quit to close the connection.

8. You can also use a mail program to send and read emails using the following command.

$ mail [email protected]

Cc: 
Subject: Testing My Postfix Mail Server
I'm sending this email using the postfix mail server from Ubuntu machine

Step 5: Installing Dovecot IMAP and POP in Ubuntu

9. Dovecot is a mail delivery agent (MDA), it delivers the emails from/to the mail server, to install it, run the following command.

sudo apt install dovecot-imapd dovecot-pop3d
Install Dovecot in Ubuntu
Install Dovecot in Ubuntu

10. Next, restart the Dovecot service and verify the status using the following commands.

sudo systemctl restart dovecot
sudo systemctl status dovecot
Check Dovecot Status
Check Dovecot Status

Step 6: Installing Roundcube Webmail in Ubuntu

11. Roundcube is the webmail server that you’ll be using to manage emails on your server, it has a simple web interface to do the job, it can be customized by installing more modules & themes.

wget https://github.com/roundcube/roundcubemail/releases/download/1.6.6/roundcubemail-1.6.6-complete.tar.gz
tar -xvf roundcubemail-1.6.6-complete.tar.gz
sudo mv roundcubemail-1.6.6 /var/www/html/roundcubemail
sudo chown -R www-data:www-data /var/www/html/roundcubemail/
sudo chmod 755 -R /var/www/html/roundcubemail/

12. Next, you need to create a new database and user for roundcube and grant all permission to a new user to write to the database.

$ sudo mysql -u root
CREATE DATABASE roundcube DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER roundcubeuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON roundcube.* TO roundcubeuser@localhost;
flush privileges;
quit;

13. Next, import the initial tables to the Roundcube database.

sudo mysql roundcube < /var/www/html/roundcubemail/SQL/mysql.initial.sql

Step 7: Create an Apache Virtual Host for Roundcube Webmail

14. Create an Apache virtual host for Roundcube webmail.

sudo nano /etc/apache2/sites-available/roundcube.conf

Add the following configuration to it.

<VirtualHost *:80>
  ServerName tecmint.com
  DocumentRoot /var/www/html/roundcubemail/

  ErrorLog ${APACHE_LOG_DIR}/roundcube_error.log
  CustomLog ${APACHE_LOG_DIR}/roundcube_access.log combined

  <Directory />
    Options FollowSymLinks
    AllowOverride All
  </Directory>

  <Directory /var/www/html/roundcubemail/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>

</VirtualHost>

15. Next, enable this virtual host and reload the Apache for the changes.

sudo a2ensite roundcube.conf
sudo systemctl reload apache2

16. You can now access the roundcube webmail by going to the following url.

http://yourdomain.com/roundcubemail/installer/
Roundcube Webmail Installer
Roundcube Webmail Installer

16. Next, go to the Database settings and add the database details.

Roundcube Webmail Database Settings
Roundcube Webmail Database Settings

17. After making all the changes, create a config.inc.php file.

Create Roundcube Configuration File
Create Roundcube Configuration File

18. After finishing the installation and the final tests please delete the installer folder and make sure that enable_installer option in config.inc.php is disabled.

$ sudo rm /var/www/html/roundcubemail/installer/ -r

19. Now go to the login page and enter the username and password of the user.

http://yourdomain.com/roundcubemail/
Roundcube Webmail Login
Roundcube Webmail Login

Step 8: Creating Mail Users in Postfix

20. In order to start using the Roundcube webmail, you’ll have to create a new user, to do so, run.

sudo useradd myusername

Replace “myusername” with the user name you want, and create a password for the new user by running.

sudo passwd myusername

21. Now go back to the login page and enter the user name and the password of the newly created user.

Have you tried to create an email server before? How did it go? Have you used Roundcube or any other mail server before? What do you think about it?

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

301 Comments

Leave a Reply
  1. Hello, I have a question.

    I don’t own a domain yet. But I wanted to know if it is possible to create a free domain such as “mydomain.com” and send emails from it? Or is it required of me to purchase the domain first?

    Reply
  2. ERROR: Config file ‘ . ‘”config/config.php” not found. You need to ‘ . ‘configure SquirrelMail before you can use it.
    ‘; exit; } // If we are, go ahead to the login page. header(‘Location: src/login.php’); ?>

    Reply
      • quanlm@web2:/var/www/html/squirrelmail⟫ ls
        class      contrib  functions  include    plugins  squirrelmail-webmail-1.4.22
        config     data     help       index.php  po       src
        configure  doc      images     locale     README   themes
        
        Reply
      • quanlm@web2:/var/www/html/squirrelmail⟫ cd config/
        quanlm@web2:/var/www/html/squirrelmail/config⟫ ls
        config_default.php  config_local.php  config.php  conf.pl  index.php
        
        Reply
    • Try this commands:

      $ sudo apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl
      $ sudo apt-get install php libapache2-mod-php
      $ sudo a2enmod mpm_prefork && sudo a2enmod php7.0
      $ sudo service apache2 restart
      
      Reply
  3. In step 14 this command usermod -m -d /var/www/html/myusername myusername is not working for me says user mod no changes.
    anyway, I’m able to log in to the error screen.
    then i use command sudo chown -R myusername:myusername /var/www/html/myusername and still get the IMAP error.

    (I’m supposed to replace my username in any of this for my actual user name ?) I’ve tried also not working.

    your help is greatly appreciated

    Reply
  4. I have completed all steps and even I remove all folder and repeat all steps carefully still I faced error:

    Error opening ../data/default_pref
    Could not create an initial preference file!
    /var/local/squirrelmail/data/ should be writable by user www-data
    

    Please contact your system administrator and report this error.

    Reply
    • @Muhammad,

      Make the following directory writable by user www-data.

      $ sudo chown -R www-data:www-data /var/local/squirrelmail/data/
      $ sudo chmod -R 776 /var/local/squirrelmail/data/
      
      Reply
      • Thank you so much, Sir,

        If I want to generate an email from laravel or python Django. How I will set laravel mail setting or Django?

        MAIL_DRIVER=smtp
        MAIL_HOST=smtp.mailtrap.io ------> what type here
        MAIL_PORT=2525   ------> port number ?
        MAIL_USERNAME=null
        MAIL_PASSWORD=null
        MAIL_ENCRYPTION=null
        

        ..
        and can you send me some tutorial or documentation of its? I am very thankful to you…

        Reply
  5. I have installed Squirrelmail as per your provided instructions. However, when I connect using Firefox I get a blank page.

    Using Chromium I get connection refused by the server.

    Reply
  6. Hello Sir,

    I have followed your instruction to create the web server. But I can’t log in with the user I created and even root. I am using a virtual host. how can I create email user on the virtual host?

    Reply
  7. Error opening ../data/default_pref
    Could not create initial preference file!
    /var/local/squirrelmail/data/ should be writable by user www-data.

    Please contact your system administrator and report this error.

    I get this error and /var/local/squirrelmail/data is not exist.

    Reply
    • What I did was that I copied “squirrelmail” folder that is in /var/www/html/squirrelmail copied to /var/local and did the permissions again, I dont know if I did it right or not but it seems to be working for me after doing that, correct if I am wrong @Ravi Saive

      Reply
      • @TechNafo,

        As per the instructions provided here, the step 4 clearly shows that squirrelmail installed under /var/www/html/squirrelmail and the data directory would be /var/www/html/squirrelmail/data.

        Reply
        • @John,

          Then, where you have installed your Squirrelmail? as per step 4 it will install under /var/www/html and data directory would be /var/www/html/squirrelmail/data.

          Reply
          • I followed step 4 and I ended up with a folder “squirrelmail” in /var/www/html/ because I was having that error I mentioned before, all that I did was copy that folder “squirrelmail” to /var/local then I ran the commands again for permissions and that was it, it was fixed for me, I dont know if I was supposed to manually copy the folder to /var/local or not but I did.

  8. I am following all the steps but I am getting this error message at the end after giving full permissions.

    Error opening ../data/default_pref
    Could not create initial preference file!
    /var/local/squirrelmail/data/ should be writable by user www-data
    Please contact your system administrator and report this error.

    I checked mail.err but nothing in there

    Reply
    • @John,

      Make the following directory writable by user www-data.

      # chown -R www-data:www-data /var/local/squirrelmail/data/
      # chmod -R 776 /var/local/squirrelmail/data/
      
      Reply
  9. It would appear that these directions are out of date or there is a repository that should be perhaps be mentioned where php5 can be obtained from.

    tcullen@tcullen-kvm1:~$ sudo apt-get install apache2 php5
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package php5 is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    
    E: Package 'php5' has no installation candidate
    
    Reply
    • @Tcullen,

      I’ve updated the article and included latest instructions for setting up complete mail server using Postfix on Ubuntu.

      Reply
  10. I have configured almost everything and also the mail is working perfectly fine but my question is can’t we install squirrel administrator for managing all the users using web ui ?

    Reply
    • Hello, @Sushant

      Based on my previous setup of email servers through this tutorial. I haven’t found any web UI for managing squirrel mail users.

      What I done is build a simple web UI and API using nodejs for CRUD users.

      Reply
  11. Hi,

    Many thanks for sharing this article.

    However, my major problem is how to point the dns to enable it work. For example, i purchased my domain from gandi.net, what configuration must i do at the domain provider’s site?
    And, how can I set up the following:

    A
    AAAA
    CNAME
    MX
    TXT
    NS
    SRV
    CAA
    

    I have an account with digitalocean.com, where I have also created a droplet and have an IP for my domain. I have created a new record at digitalocean.com and I have changed the dns server information at gandi.net as ns1.mydomain.com and ns2.mydomain.com.

    I have already setup Postfix Mail Server on my Ubuntu 14, although, without installing the squirrel mail, but while i was researching how to fix the above, i came across this post and i find it very helpful because I was able to add Squirrel Mail to my Postfix Mail, but still, nothing is working.

    Please I really need your help to fix this.

    Reply
  12. Hi ,

    When I try to send any mail I got an error like:

    “Service not available, closing channel
    421 4.3.0 collect: Cannot write ./dfwAKAhJ3f108965 (bfcommit, uid=0, gid=119): No such file or directory”

    Is there anybody give me a hand to rid out of it .

    Thank

    Reply
  13. Hi Zac, I still have the error even though I added my user to the mail group. From my /var/llog/mail.err, I am getting this:

    localhost dovecot: imap(myusername): Error: Opening INBOX failed: Mailbox isn’t selectable

    Reply
  14. Hello

    During the installation of Dovecot did not execute the creation of SSL keys, how do I create at this time?

    Another thing, following step by step, I still have a problem logging in to squirrelmail: ERROR: Connection dropped by IMAP server.

    Can you help me?

    Thank you.

    Reply
    • Have you checked the log at /var/log/mail.err?

      Maybe the permission or the existence of the folder is missing in /var/mail/myusername?

      I still have the error though on localhost dovecot: imap(myusername): Error: Opening INBOX failed: Mailbox isn’t selectable.

      Reply
  15. When I tried to create a MX record on my server on DigitalOcean, there is a session that says [MAIL PROVIDERS MAIL SERVER] and the example in that field reads aspmx.|.google.com.

    Reply
  16. @Rahu

    I tried to send an email using the newly setup email server but, I don’t receive any email in my gmail. Does MX and SPF record, took times or days to be able my newly setup server to send email ?

    Reply
    • Hi Chael. Both the MX and SPF records will take about two hours (depending on your location) to propagate to other DNS servers. I’ve heard of some cases of it taking a day, but not more than that.

      Reply
      • @doug can you help me setup a simple email server ?

        I already follow the tutorial and I receive email but sending email to my gmail doesn’t work.

        I don’t know if I miss something from my dns config, [email protected] is my email. if you can help me

        Reply
  17. Hi, How do I link it up with SQL so that users will have the freedom to reset their passwords to their choice? and enable password reset option in the web interface?

    Reply
  18. Good tutorial, but I still get a time-out “ERROR: Connection dropped by IMAP server.”. Any ideas would be appreciated.

    Reply
      • Can your please explain that MX record and SPF record for my domain? Am using digitalocean and followed all above steps.

        Reply
        • @Rahu

          MX (mail exchange) record is an entry in your DNS zone file that specifies a mail server to handle a domain’s email, and SPF(Sender Policy Framework) record is an entry in DNS zone file used to indicate to mail exchanges which hosts are authorized to send mail for a domain.

          Reply
        • @Rahu

          You will need (must have) a MX record in your DNS configuration. An example would be:

          MX   10   mail.your-domain-name.com
          

          A SPF (Sender Policy Framework) helps other email servers (like Gmail) to let them know that you are a legitimate email server and not pumping out spam. A SPF record would look something like this:

          v=spf1 mx include:your-domain-name.com -all 
          

          This is the one that I use and it has passed all spam filters and gmail.

          Reply
  19. Hi! I would like to ask what I should do if I have already installed an SSL certificate. Should I install a new certificate during the Dovecot installation or I could expand my certificate.

    Reply
  20. On SquirrelMail, I get an error:

    ERROR: Could not complete request.
    Query: SELECT “INBOX”
    Reason Given: [SERVERBUG] Internal error occurred. Refer to server log for more information. [2018-04-06 18:33:43] (0.000 + 0.000 secs).

    Reply
  21. Dec 29 10:21:44 presta-final dovecot: imap-login: Fatal: Can’t load ssl_cert: There is no valid PEM certificate. (You probably forgot ‘<' from ssl_cert=<)

    I am facing problem regrading ssl certificate, help me!

    Reply
  22. Hey i have set up the mail server using this tutorial, now i ab able to send the mails, but not being able to receive the mails, can anyone help me in that, i think its MX record problem in DNS, so what should i put in MX record in DNS ?

    Reply
  23. My squirrel mail is not working from last 10 days. It shows “Unknown user or password incorrect

    Please tell me step by step troubleshooting.

    Reply
  24. Hi there, How can i add auto response feature in squirrel mail, I know that we can add from backend by installing auto response package, but How can we add auto response plugin to squirrel mail?

    Reply
  25. Thank you for the amazing tutorial,

    I have been trying to setup my email server for as long as i can remember, and i never got it right until this time.

    Reply
  26. The steps are missing to give the username permissions to create an Inbox.

    https://serverfault.com/questions/713635/postfix-dovecot-squirrelmail-failed-to-autocreate-mailbox-inbox

    The first line of the dovecot error indicates it doesn’t have permission write to /var/mail/. This indicates the dovecot is running under an account without permission to write to the folder. /var/mail/ is owned by root:mail (UID/GID 0:8), giving full read/write/execute permissions to both root and the group mail.

    Dovecot is running under nicolai to access it, and because nicolai is not in the group mail, the folder cannot be accessed.

    I’m not sure how the other inbox folders got created, but to fix this, all you should need to do is add nicolai to mail, like this:

    # adduser nicolai mail
    

    That should allow nicolai to access it’s mail folder, and fix the problem.

    Reply
  27. When I try to log into my Squirrelmail web interface there comes this:
    Error connecting to IMAP server: timetoplaymc.de.
    111 : Connection refused

    What can I do? What is wrong?

    Reply
  28. May 30 15:19:05 mailaitlb dovecot: imap(myusername): Error: open(/var/mail/myusername) failed: Permission denied (euid=1003(myusername) egid=1003(myusername) missing +w perm: /var/mail, we’re not in group 8(mail), dir owned by 0:8 mode=0775)
    May 30 15:19:05 mailaitlbdovecot: imap(myusername): Error: Failed to autocreate mailbox INBOX: Internal error occurred. Refer to server log for more information. [2017-05-30 15:19:05]

    I’m getting this error. Please help me.

    Reply
  29. Hello After completion of all the step mention. I wanted to access the server through browser but it showing not found. Can you assist

    Reply
  30. my domain name is dima.lb
    I try to send mail but the same error appear every time : “Requested action not taken: mailbox unavailable 550 5.1.1 : Recipient address rejected : gmail.com”

    Can anyone help me

    Reply
    • what I have found is that this is most likely gmail’s spam filter blocking you. This is usually for new domains and stuff. To test this send an email to a yahoo account and see if it goes through. I have yet to find a fix for this issue though.

      Reply
      • I meant spam filter, not firewall. *sigh* This is why you should always proofread things and why forums and comment sections should always have an edit button.

        Reply
  31. Hi Sir,

    This is very nice guide, I’ve don the configuration, unable to login with domain. Can you please help me, how to login with domain. How to enable virtual domain. Please help me, this is very nice really very great sir.

    Reply
  32. Hi,

    Thanks for the tutorial. Is this possible to install on the same server as my website? I use nginx and ruby on rails on my website. If I install this, will it not be causing conflicts?

    Thanks

    Reply
    • @Clint,

      You can install Postfix on same Linux server without any issues, it will not conflict with your web server or applications..

      Reply
  33. Please create user with these step,
    # useradd username
    # passwd usernmae
    # cd /home
    # cd username
    # mkdir mail
    # cd mail
    # mkdir .imap
    # cd imap
    # cd .imap

    Please do it step by step and dont try to create directory like /home/username/mail

    You can say it is crazy but I did face same problem and I fix it the say way.

    Regard
    # mkdir INBOX/
    # cd INBOX

    Reply
  34. Hello,
    thank for tuto :)
    in the final step i got this error :
    ERROR: Could not complete request.
    Query: SELECT “INBOX”
    Reason Given: [SERVERBUG] Internal error occurred. Refer to server log for more information. [2016-09-11 16:04:43]

    i use ubuntu 14.04

    Best regards,

    Reply
  35. I gave the domain name as superstar.org. Now when I type superstar.org/squirrelmail in the browser,I just get a blank screen.what should I do ?

    Reply
    • Did you manage to solve this issue.
      Because I’m not getting redirected to the squirrelmail login page after typing this in browser’s address bar

      Reply
  36. In install devcot step system didn’t asked for create a self-signed SSL certificate
    Any one having any Idea why this happened ?
    Does it will create any problem?

    Reply
  37. Hey guys,

    First of all thank you very much for this genius tutorial =) With this step-by-step procedure it was quite easy to set up a Mail Server.

    But I think there is a little mistake in the $ usermod -m -d /var/www/html/myusername command. ( It didn’t work for me and since I am a Linux-newbie i didn’t notice it at first so I had to ask a colleague).

    He told me that it should be : “$ usermod -m -d /var/www/html/myusername myusername“.

    I hope this will help some of the newbies to come =)

    Have a nice day =)

    Reply
    • @Chris,

      Your colleague is absolutely correct, the command should be:

      $ usermod -m -d /var/www/html/myusername myusername
      

      As per you commands suggestions, I’ve corrected the command in the writeup..

      Reply
  38. Hello every one, could you help me please, i not speak or write english perfectly, but i will try. I have an error when i try to login trough the web browser, the error says: NOT FOUND The requested URL /webmail/ was not found.

    please help me

    regards

    Reply
  39. Do you have correct MX record set for you domain in DNS control panel? if not, please set it first to receive mails from outside domains..

    – This is my set-up. I created two separate servers for app and mail in AwS. My app server owns the domain. In my mail server, I installed Postfix, dovecot and squirrelMail. Now the problem is how can I now set the MX record? Please help. Thanks

    Reply
    • @Marsha,

      Go to your domain control panel, where you’ve purchased domain and add the MX record like mail.domain.com with priority 10 and 20..

      Reply
    • @Marsha,

      Do you have correct MX record set for you domain in DNS control panel? if not, please set it first to receive mails from outside domains..

      Reply
  40. i have install the squirrel mail in Ubuntu VM but i getting the error unknown user or password incorrect on login time please help

    Reply
  41. @Ravi Saive,

    Question
    I have a postfix server which is running on Ubuntu,Somehow my server is blacklisted with some xxx.com due this the xxx.xom is not allowing incoming emails from my server. so can I forward the emails which are in queue (postfix) to another postfix server to send those deffered emails ?

    Can someone help me how can I achieve this ?

    Reply
      • @Ravi Saive,

        Thank you for your prompt reply. The relay option which you are referring to is “relayhost” in postfix main.cf file ?
        If yes if I add the IP to the relayhost parameter will that do the trick ?

        Thank you in advance.

        Reply
  42. that command doesn’t work for me
    usermod -m -d /var/www/html/myusername

    Usage: usermod [options] LOGIN

    Options:
    -c, –comment COMMENT new value of the GECOS field
    -d, –home HOME_DIR new home directory for the user account
    -e, –expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
    -f, –inactive INACTIVE set password inactive after expiration
    to INACTIVE
    -g, –gid GROUP force use GROUP as new primary group
    -G, –groups GROUPS new list of supplementary GROUPS
    -a, –append append the user to the supplemental GROUPS
    mentioned by the -G option without removing
    him/her from other groups
    -h, –help display this help message and exit
    -l, –login NEW_LOGIN new value of the login name
    -L, –lock lock the user account
    -m, –move-home move contents of the home directory to the
    new location (use only with -d)
    -o, –non-unique allow using duplicate (non-unique) UID
    -p, –password PASSWORD use encrypted password for the new password
    -R, –root CHROOT_DIR directory to chroot into
    -s, –shell SHELL new login shell for the user account
    -u, –uid UID new UID for the user account
    -U, –unlock unlock the user account
    -v, –add-subuids FIRST-LAST add range of subordinate uids
    -V, –del-subuids FIRST-LAST remvoe range of subordinate uids
    -w, –add-subgids FIRST-LAST add range of subordinate gids
    -W, –del-subgids FIRST-LAST remvoe range of subordinate gids
    -Z, –selinux-user SEUSER new SELinux user mapping for the user account

    Reply
  43. Hi,

    I am stuck at this screen even after you suggest the command, still getting the same error:

    ERROR: Connection dropped by IMAP server

    Reply
    • @Anand,

      To fix such issue, open the /etc/dovecot/dovecot.conf file and add the following line in the IMAP section:

      protocol imap {
      mail_location = mbox:~/mail:INBOX=/var/mail/%u
      }
      

      Restart dovecot:

      # /etc/init.d/dovecot restart
      
      Reply
      • Hi, Thanks for the reply and instruction.

        there is no IMAP section in default /etc/dovecot/dovecot.conf, but I have added the above line in /etc/dovecot/conf.d/20-imap.conf.

        Still no luck, getting same error.

        Reply
        • No need for what he told you here is easy way

          Added to /etc/dovecot/conf.d/10-mail.conf
          mail_location = maildir:~/Maildir

          and 100% it will work i followed the tutorial to but i got this mistake untill i searched the error in mail.log and this was the solution

          Reply
    • Hi, Now I am getting different error after I restarted the System.

      Error connecting to IMAP server: localhost.
      111 : Connection refused

      Reply
      • @Anand,

        Better, could you post output of the web mail server’s log file for IMAP server: localhost error by executing the following commands:

        # cd /var/log/
        # cat maillog* | grep drop -i
        
        Reply
    • @Matt,

      Yes I completely agree with your suggestion that this guide really needs an update and we’re in process to update this article with new instructions very soon. Also if you’ve anything in mind that needs to be added to this article, do suggest us..

      Reply
  44. Hi there,
    I followed the instruction until step 14 where I’ve got 404 error trying access to mydomain.com/squirrelmail.
    Do you have any suggestions?
    Thank you

    Reply
    • @Gio,

      Have you checked in “/var/log/mail.err” file for any error messages, if not please check and correct it or if possible could you post the mail.err logs here.

      Reply
  45. Do you have a tutorial on how to setup such mail client on centOS 7?
    Can I create unlimited email account with such tutorial?

    Reply
  46. i have configured squirrelmai on 2 system , i follow all the step one by one ,i am able to send mail to local user or other domain user but i am not able to receive email from other domain user .

    Reply
      • same issue is happening to me :( . i am able to send mail to gmail user but i am not able to receive email from it.
        Gmail error :
        The error that the other server returned was:
        Recipient not found. .

        Reply
  47. It Works!! Many thanks.
    The Squirrelmail works perfectly!
    But when i try set an account using Thunderbird, the /etc/log/mail.log say
    Nov 28 00:46:44 ip-172-31-44-39 postfix/submission/smtpd[13614]: improper command pipelining after EHLO from unknown[159.16.X.X]: QUIT\r\n

    Any Idea!
    Regards!

    Reply
  48. It gives me a SQL error
    ERROR: Could not complete request.
    Query: SELECT “INBOX”
    Reason Given: [SERVERBUG] Internal error occurred. Refer to server log for more information. [2015-11-15 23:27:29

    Reply
      • I had a similar error and this is the log:
        imap(marclar): Error: open(/var/mail/marclar) failed: Permission denied (euid=1007(marclar) egid=1007(marclar) missing +w perm: /var/mail, we’re not in group 8(mail), dir owned by 0:8 mode=0775)
        Jan 6 00:07:50 jasonrules dovecot: imap(marclar): Error: Failed to autocreate mailbox INBOX: Internal error occurred. Refer to server log for more information. [2016-01-06 00:07:50]

        Reply
        • @Jason,

          Open and add the group mail to the line “mail_privileged_group = ” in /etc/dovecot/conf.d/10-mail.conf file, then stop and restart the dovecot Hope it will solve this error.

          Reply
  49. I can host my email server, in Ubuntu 14, first it is not gui, my site is hosted anywhere else, i want to make my own email server, with already hosted site that is with third party now.

    Reply
  50. Hi, I have ran the command: sudo chown -R myusername:myusername /var/www/html/myusername (with my correct user name), yet i still keep getting the “ERROR: Connection dropped by IMAP server”

    I have checked and I have both IMAP (port 143) and IMAPS (port 993) open (i am doing this on an azure linux vm, so they are set up as endpoints on the vm)

    any suggestion on what else i would need to do?

    Reply
    • @Dave,

      To resolve such an error open dovecot.conf file and add the following line in the IMAP section:

      protocol imap {
      mail_location = mbox:~/mail:INBOX=/var/mail/%u
      }
      

      If the above solution doesn’t work try to increase the client_limit from 100 to 1000 in same dovecot.conf file.

      If any of the above solution, doesn’t resolve your problem, you should check out the Squirrelmail IMAP problem guide at

      http://squirrelmail.org/wiki/MailServerIMAPProblem

      Reply
  51. hello, i followed procedure, but when I try to access mail server: ERR_NAME_NOT_RESOLVED, impossible to find DNS.
    I registered a domain and I think I should use default DNS.
    Thanks to everyone

    Reply
        • @Giuseppe,
          Does your domain resolves to your server IP address? I am sure your domain DNS is not properly set in your DNS manager of your domain hosting..

          Reply
          • mmm I dont know…So what do I should do? Changing default domain settings using my IP settings? If it’s correct, how can I do that? Thanks and sorry for the questions :)

          • @Giuseppe,
            Very difficult me to help you friend, no problem could you please tell me your domain name? so that I can do some DSN testing on my end..After that I can provide you correct solution.

          • @Giusseppe,
            I check your domain not resolving properly, you need to set A record and point the domain to Server IP address to work everything perfectly, I suggest you to consult your DNS provider..

          • ok, thank you very much, the problem is that I just buyed domain and I need an hosting service. But I would not buy an hosting and do it by myself.

  52. Hi everyone! I’m having some issues during the set up process. I do every step as it’s explained here but when I wanna go to example.com/squirrelmail it throws me 404 error. I’ve noticed that Squirrelmail is installed in /etc/squirrelmail… and I think… how could I in any way link those 2 folders to work together? I don’t know if I’m clear. I want to link /etc/squirrelmail with /var/www/username where my server is, to make squirrelmail work from there. So that way I could access. I’ve tried command ln folder folder but it says it’s impossible to make a hard link between folders…. so I’ve tried ln -s folder folder… but it’s still not working.

    Any help would be very appreciated.

    Reply
    • @Carolina,

      Have you copied default squirremail Apache configuration file under apache2 directory in order to access the squirrelmail web? if not do,

      $ sudo cp /etc/squirrelmail/apache.conf /etc/apache2/sites-available/squirrelmail.conf
      

      And enable it using:

      $ sudo a2ensite squirrelmail.conf
      

      Now try to access the web page of squirremail again and see..

      Reply
  53. Hello, thia article was very helpful, thanks a ton.
    i m getting a mail to my spam box.
    1> I m sending to gmail account
    2> i am not able to send mail back to the user from gmail account ,
    it says as
    Delivery to the following recipient failed permanently:

    [email protected]

    Technical details of permanent failure:
    Google tried to deliver your message, but it was rejected by the server for the recipient domain mydomain.com by aspmx.l.google.com. [2607:f8b0:4003:c0a::1b].Delivery to the following recipient failed permanently:

    [email protected]

    Technical details of permanent failure:
    Google tried to deliver your message, but it was rejected by the server for the recipient domain inertiagroups.com by aspmx.l.google.com. [2607:f8b0:4003:c0a::1b].

    Reply
    • @Lokendra,
      Firstly, you must have a Mail MX record for you mail domain to deliver mails to user inbox, and secondly a user must exists on the system to receive mail from outside, if user do not exists you will get a message as stated in your question..

      Reply
      • I can only login with localhost/squirrelmail and send email . but when I login with example.com/squirrelmail I’ve got 404 error. I set my IP in sever and 25 port .

        Reply
        • @Hamid,
          I think you should check that your domain example.com is resolving DNS properly? have you correctly configured Apache to server squirrelmail?

          Reply
  54. Hi.I got this error when login
    “ERROR: Could not complete request.
    Query: SELECT “INBOX”
    Reason Given: [SERVERBUG] Internal error occurred. Refer to server log for more information”

    Reply
  55. I am stuck at step 16, First part ok, it creates the folder but each time i run the usermod, it simply show a list of correct way to run command. it does nothing else. ANy tip for that?

    Reply
      • I felt your pain. The correct syntax of the command is “sudo usermod -m -d /var/www/html/username username”. The ” username” (note the leading space) was omitted.

        I also had to make the following modifications in /etc/dovecot/conf.d/10-mail.conf:

        mail_location = mbox:~/mail:INBOX=/var/mail/%n
        mail_privileged_group = mail

        At the moment, SquirrelMail works, but the “Check mail” link does not refresh my INBOX. However, clicking the “INBOX” link in the left pane does refresh my mail.

        Reply
  56. Hi,

    Great article but even after giving ‘myusername’ full access to its homedir I still get

    ‘ERROR: Connection dropped by IMAP server.’

    Anything else I can try?

    Reply
  57. When installing postfix I never got to the configuration screen “During installation, you will be asked to choose the default file configuration for your server.” Therefore I never was able to setup the domain name or user. How can I get that dialog?

    Reply
  58. Hello , can anyone help me with this error pls ?

    May 8 12:34:36 Server dovecot: imap(faxarena): Error: user faxarena: Initialization failed: Namespace ”: mkdir(/var/www/html/mail) failed: Permission denied (euid=1019(faxarena) egid=1019(faxarena) missing +w perm: /var/www/htm$
    May 8 12:34:36 Server dovecot: imap(faxarena): Error: Invalid user settings. Refer to server log for more information.
    May 8 12:37:05 Server dovecot: imap(faxarena): Error: user faxarena: Initialization failed: Namespace ”: mkdir(/var/www/html/mail) failed: Permission denied (euid=1019(faxarena) egid=1019(faxarena) missing +w perm: /var/www/htm$
    May 8 12:37:05 Server dovecot: imap(faxarena): Error: Invalid user settings. Refer to server log for more information.
    May 8 12:37:09 Server dovecot: imap(faxarena): Error: user faxarena: Initialization failed: Namespace ”: mkdir(/var/www/html/mail) failed: Permission denied (euid=1019(faxarena) egid=1019(faxarena) missing +w perm: /var/www/htm$
    May 8 12:37:09 Server dovecot: imap(faxarena): Error: Invalid user settings. Refer to server log for more information.

    Reply
  59. Why my way for mail /home/myusername and not /var/www/html/myusername?
    I must exchange the way for email work.
    Thanks.

    Reply
  60. hi , i need to do this tutorial for nginx, not for apache2, because i use nginx and i don’t have apache2 installed on my server dedicated. i want to login with e-mail adress like ([email protected] and password) , not with username and password, to use my e-mail adress in outlook . How i doo this? Kane you make a tutorial like this one? But with nginx instead apache2 and for debian 7 x86?
    Ty and sorry for my bad english.

    Reply
  61. your tutorial is nice here. you just forget this piece for squirrel mail

    sudo ln -s /etc/apache2/sites-available/squirrelmail /etc/apache2/sites-enabled/squirrelmail

    Reply
  62. I have the problem that after every step still tells me.

    Forbidden

    You don’t have permission to access /squirrelmail on this server.

    Reply
  63. Hi,
    I found your article from Technotes blog. I followed your instruction smoothly until the step “sudo an2ensite squirrelmail.conf”. I got the response that “-bash: an2ensite: command not found”. Could you let me know what I should do to fix that? Thanks.

    Reply
    • @Deepanjan,
      This guide is specially for Debian based distros, it will won’t work on CentOS, we are in process of creating a complete mail server setup in CentOS…stay tuned for this article..

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.